【发布时间】:2014-08-23 20:12:17
【问题描述】:
我在使用 google appengine 时遇到问题,我无法使用 python 的 put() 命令初始化任何表
这是我的代码:
import webapp2
import datetime
from google.appengine.ext import db
from google.appengine.api import users
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
class Employee(db.Model):
name = db.StringProperty(required=True)
role = db.StringProperty(required=True,
choices=set(["executive", "manager", "producer"]))
hire_date = db.DateProperty()
new_hire_training_completed = db.BooleanProperty(indexed=False)
email = db.StringProperty()
e = Employee(name="John",
role="manager",
email="joe@joe.com")
e.hire_date = datetime.datetime.now().date()
e.put()
错误如下:
Traceback (most recent call last):
File "C:\python27_x64\blog\blog\main.py", line 46, in <module>
e.put()
File "C:\python27_x64\lib\google\appengine\ext\db\__init__.py", line 1069, in put
self._populate_internal_entity()
File "C:\python27_x64\lib\google\appengine\ext\db\__init__.py", line 1038, in _populate_internal_entity
self._entity = self._populate_entity(_entity_class=_entity_class)
File "C:\python27_x64\lib\google\appengine\ext\db\__init__.py", line 1107, in _populate_entity
entity = _entity_class(self.kind(), **kwds)
File "C:\python27_x64\lib\google\appengine\api\datastore.py", line 759, in __init__
_app = datastore_types.ResolveAppId(_app)
File "C:\python27_x64\lib\google\appengine\api\datastore_types.py", line 228, in ResolveAppId
ValidateString(app, 'app', datastore_errors.BadArgumentError)
File "C:\python27_x64\lib\google\appengine\api\datastore_types.py", line 176, in ValidateString
raise exception('%s must not be empty.' % name)
BadArgumentError: app must not be empty.
感谢您的帮助。
【问题讨论】:
-
你的 app.yaml 是什么样的?
-
您是通过 dev_appserver 运行代码,还是直接使用 python?
-
我直接使用 python 运行并使用 paste 来初始化一个 http 服务器。 APP.YAML IS:应用程序:udacity-cs253 版本:1 运行时:python27 api_version:1 线程安全:true 处理程序:-url:/static static_dir:静态-url:/.* 脚本:blog.app 库:-名称:jinja2 版本:最新 - 名称:PIL 版本:“1.1.7”
-
你应该使用 dev_appserver: developers.google.com/appengine/docs/python/…
-
我知道我很迂腐,但数据存储区中没有“表”。您无法初始化模型,这纯粹是您的代码级别,而不是数据存储级别的强制执行。您是否绝对确定上面的代码是从您的代码而不是示例文档中粘贴的。最后,如果您刚开始使用 appengine 和数据存储,那么我强烈建议您立即停止使用 db,并学习 ndb 教程。 ndb 是几乎所有应用程序的更好的 api。
标签: python google-app-engine google-cloud-datastore