我正在使用kamalgill的flask-appengine-template并遇到一个奇怪的问题。
我的models.py
文件如下所示:
from google.appengine.ext import ndb
class DimensionModel(ndb.Model):
""""""
value=ndb.FloatProperty(required=True)
tolerance=ndb.FloatProperty(required=True)
class StackModel(ndb.Model):
"""Example Model"""
example_name = ndb.StringProperty(required=True)
example_description = ndb.TextProperty(required=True)
dimensions=ndb.KeyProperty(kind='DimensionModel')
added_by = ndb.UserProperty()
timestamp = ndb.DateTimeProperty(auto_now_add=True)
我的forms.py
文件如下所示:
from flaskext import wtf
from flaskext.wtf import validators
from wtforms.ext.appengine.ndb import model_form
from .models import StackModel
# App Engine ndb model form example
ExampleForm = model_form(StackModel, wtf.Form, field_args={
'example_name': dict(validators=[validators.Required()]),
'example_description': dict(validators=[validators.Required()]),
})
这给了我下面显示的错误转储。如果我只是在models.py中注释掉dimensions=ndb.KeyProperty(kind='DimensionModel')
行,那么一切正常。我不知道从哪里开始。
INFO 2013-06-16 06:02:20,592 sdk_update_checker.py:244] Checking for updates to the SDK.
INFO 2013-06-16 06:02:20,886 api_server.py:153] Starting API server at: http://localhost:39407
INFO 2013-06-16 06:02:20,938 dispatcher.py:164] Starting server "default" running at: http://localhost:8080
INFO 2013-06-16 06:02:20,947 admin_server.py:117] Starting admin server at: http://localhost:8000
ERROR 2013-06-16 06:02:22,888 wsgi.py:219]
Traceback (most recent call last):
File "/home/chris/google_appengine/google/appengine/runtime/wsgi.py", line 196, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/chris/google_appengine/google/appengine/runtime/wsgi.py", line 255, in _LoadHandler
handler = __import__(path[0])
File "/home/chris/code/flask-appengine-template_running/src/run.py", line 5, in <module>
import application
File "/home/chris/code/flask-appengine-template_running/src/application/__init__.py", line 23, in <module>
import urls
File "/home/chris/code/flask-appengine-template_running/src/application/urls.py", line 10, in <module>
from application import views
File "/home/chris/code/flask-appengine-template_running/src/application/views.py", line 20, in <module>
from forms import ExampleForm
File "/home/chris/code/flask-appengine-template_running/src/application/forms.py", line 21, in <module>
'example_description': dict(validators=[validators.Required()]),
File "/home/chris/code/flask-appengine-template_running/src/lib/wtforms/ext/appengine/ndb.py", line 403, in model_form
field_dict = model_fields(model, only, exclude, field_args, converter)
File "/home/chris/code/flask-appengine-template_running/src/lib/wtforms/ext/appengine/ndb.py", line 370, in model_fields
field = converter.convert(model, props[name], field_args.get(name))
File "/home/chris/code/flask-appengine-template_running/src/lib/wtforms/ext/appengine/ndb.py", line 179, in convert
return converter(model, prop, kwargs)
File "/home/chris/code/flask-appengine-template_running/src/lib/wtforms/ext/appengine/ndb.py", line 327, in convert_KeyProperty
kwargs['reference_class'] = prop._reference_class
AttributeError: 'KeyProperty' object has no attribute '_reference_class'
INFO 2013-06-16 06:02:22,898 server.py:585] default: "GET /_ah/warmup HTTP/1.1" 500 -
答案 0 :(得分:4)
# App Engine ndb model form example
ExampleForm = model_form(StackModel, wtf.Form, only =('example_name', 'example_description'),
field_args={
'example_name': dict(validators=[validators.Required()]),
'example_description': dict(validators=[validators.Required()]),
})
使用“only”来限制表单使用的字段。
这有效!