Google app engine 如何使用python-google应用程序引擎将表单中的数据放入数据存储

Google app engine 如何使用python-google应用程序引擎将表单中的数据放入数据存储,google-app-engine,google-cloud-datastore,Google App Engine,Google Cloud Datastore,我是谷歌应用程序引擎的初学者,我有这个问题 我尝试创建一个表单,并在提交时将所有数据放入数据存储。对于exmble class Book(db.Model): #book_id = db.key title = db.StringProperty() author = db.StringProperty() #copies = db.IntegerProperty() category = db.StringProperty() class GuestB

我是谷歌应用程序引擎的初学者,我有这个问题

我尝试创建一个表单,并在提交时将所有数据放入数据存储。对于exmble

class Book(db.Model):
    #book_id = db.key
    title = db.StringProperty()
    author = db.StringProperty()
    #copies = db.IntegerProperty()
    category = db.StringProperty()

class GuestBook(webapp.RequestHandler): def get(self):
        self.response.out.write("""
      <html>
        <body>
          <form action="/sign" method="post">
            <div>Title: <input type="text" name="title"</div>
    <div>Author: <input type="text" name="author"</div>
    <div>Copies: <input type="text" name="copies"</div>
    <div><select>
        <option name="category" value="adventure">Adventure</option>
        <option name="category" value="comedy">Comedy</option>
        <option name="category" value="dramatic">Dramatic</option>
        <option name="category" value="mystery">Mystery</option>
        <option name="category" value="science_fiction">Science Fiction</option></select>
    <div><input type="submit" value="Add Book"></div>
          </form>
        </body>
      </html>""")
但我有这些

    Traceback (most recent call last):
  File "/home/kostas89/google_appengine/google/appengine/ext/webapp/__init__.py", line 636, in __call__
    handler.post(*groups)
  File "/home/kostas89/library/library.py", line 59, in post
    book.put()
  File "/home/kostas89/google_appengine/google/appengine/ext/db/__init__.py", line 984, in put
    return datastore.Put(self._entity, config=config)
  File "/home/kostas89/google_appengine/google/appengine/api/datastore.py", line 455, in Put
    return _GetConnection().async_put(config, entities, extra_hook).get_result()
  File "/home/kostas89/google_appengine/google/appengine/datastore/datastore_rpc.py", line 629, in get_result
    self.check_success()
  File "/home/kostas89/google_appengine/google/appengine/datastore/datastore_rpc.py", line 599, in check_success
    rpc.check_success()
  File "/home/kostas89/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 558, in check_success
    self.__rpc.CheckSuccess()
  File "/home/kostas89/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl
    self.request, self.response)
  File "/home/kostas89/google_appengine/google/appengine/api/datastore_file_stub.py", line 710, in MakeSyncCall
    response)
  File "/home/kostas89/google_appengine/google/appengine/api/apiproxy_stub.py", line 87, in MakeSyncCall
    method(request, response)
  File "/home/kostas89/google_appengine/google/appengine/api/datastore_file_stub.py", line 793, in _Dynamic_Put
    self.__WriteDatastore()
  File "/home/kostas89/google_appengine/google/appengine/api/datastore_file_stub.py", line 643, in __WriteDatastore
    self.__WritePickled(encoded, self.__datastore_file)
  File "/home/kostas89/google_appengine/google/appengine/api/datastore_file_stub.py", line 699, in __WritePickled
    os.rename(tmp_filename, filename)
OSError: [Errno 21] Is a directory
所以我确信这种“方式”(我在论坛上找到的)是完全错误的。关于如何放置数据以及如何检索数据(但这是另一个故事)有什么建议吗?
感谢您的建议。

您应该为创建的实例赋值

class Add(webapp.RequestHandler):
  def post(self):
    book = Book() 
    book.title = self.request.get('title')
    book.author = self.request.get('author')
    book.category = self.request.get('category')        
    book.put()

看起来您在命令行上为
dev_appserver
指定了一个数据存储路径,并且您指定的路径指向一个目录,而不是一个文件。尝试修复此问题,或者完全删除此参数。

谢谢,我只需赋值,就完成了!另外,我需要显示结果,并且我正在尝试使用fetch()方法,但是我又出现了一些错误(我也尝试了其他方法,但仍然没有结果)。再次感谢@如果你觉得这个答案有用,你应该把它标记为接受。如果你有更多的问题要问,请打开另一个问题。
class Add(webapp.RequestHandler):
  def post(self):
    book = Book() 
    book.title = self.request.get('title')
    book.author = self.request.get('author')
    book.category = self.request.get('category')        
    book.put()