gpt4 book ai didi

python - 使用 flask-appengine-template 时奇怪的 KeyProperty 失败

转载 作者:行者123 更新时间:2023-11-28 22:55:15 25 4
gpt4 key购买 nike

我正在使用 flask-appengine-template来自 kamalgill,我遇到了一个奇怪的问题。

我的 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 -

最佳答案

# 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” 来限制表单要使用的字段。

这行得通!

关于python - 使用 flask-appengine-template 时奇怪的 KeyProperty 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17130717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com