在Google App Engine中使用Python的多个ndb.model类
我刚接触GAE和Python,正在学习谷歌提供的教程。不过,当我尝试在同一个文件中创建多个模型类时,就遇到了问题。如果我添加了这样的代码:
class Greeting(ndb.Model):
"""Models an individual Guestbook entry with author, content, and date."""
author = ndb.UserProperty()
content = ndb.StringProperty(indexed=False)
email = ndb.StringProperty()
date = ndb.DateTimeProperty(auto_now_add=True)
colours = ndb.StringProperty(repeated=True)
class UserInformation(ndb.model):
username = ndb.UserProperty()
firstname = ndb.StringProperty(required=True)
lastname = ndb.StringProperty(required=True)
telephone = ndb.IntegerProperty()
我就会收到以下错误信息:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
File "C:\Python27\gae\listproperty\main.py", line 37, in <module>
class UserInformation(ndb.model):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
如果我把UserInformation类放到第二个文件中,然后尝试在main.py中导入它,我又会收到类似的错误信息。
我想知道在GAE中使用Python处理多个ndb.model类的最佳方法是什么?
任何帮助都非常感谢。
1 个回答
10
你写错字了,把这一行:
class UserInformation(ndb.model):
改成(注意大写的 M
):
class UserInformation(ndb.Model):
这样就应该没问题了。