-2

フォームで copyright_year として 1933 を入力すると、次のエラーが表示されます。

ファイル「C:\programming_google_app_engine_repo\datastore\main.py」、29 行目、投稿 book.copyright_year = int(self.request.get('copyright_year')) ValueError: 基数 10 の int() の無効なリテラル: '1933 1655'

このエラーが発生するのはなぜですか?

main.py

import webapp2
import jinja2
import os

from google.appengine.ext import db

jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

class MainPage(webapp2.RequestHandler):
    def get(self):          

        book_query1 = Book.all()
        shakespeare_books = book_query1.filter("author =", "William Shakespeare")

        template_values = {
            'shakespeare_books': shakespeare_books,             
        }

        template = jinja_environment.get_template('index.html')
        self.response.out.write(template.render(template_values))


class BookStore(webapp2.RequestHandler):
    def post(self):
        book = Book()
        book.title = self.request.get('title')
        book.author = self.request.get('author')
        book.copyright_year = int(self.request.get('copyright_year'))       
        book.put()  
        self.redirect('/')      


class Book(db.Model):
    title = db.StringProperty()
    author = db.StringProperty()
    copyright_year = db.IntegerProperty()



app = webapp2.WSGIApplication([('/', MainPage),
                                ('/new_book',BookStore)], debug=True)

index.html

<html>
    <body>                      
        <form action="/new_book" method="post">         
            <label for="title">Title</label>
            <div><textarea name="title" rows="1" cols="20" id="title"></textarea></div>
            <label for="author">Author</label>
            <div><textarea name="author" rows="1" cols="20" id="author"></textarea></div>
            <label for="copyright_year">Copyright Year</label>
            <div><textarea name="copyright_year" rows="1" cols="20" id="copyright_year"></textarea></div>           
            <div><input type="submit" value="Submit"></div>
        </form>

        {% for books in shakespeare_books %}                    
                <b>{{ books.title }}</b> 
                <b>{{ books.author }}</b>
                <b>{{ books.copyright_year }}</b>               
                <hr></hr>           
        {% endfor %}
    </body>
</html>
4

1 に答える 1