我有以下模型:
class Post(Document):
body = db.StringField(required=True)
author = db.StringField(verbose_name="Author", max_length=255, required=True)
created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
comments = db.ListField(db.EmbeddedDocumentField('Comment'))
和以下观点:
from flask.ext.mongoengine.wtf import model_form
@app.route('/')
def home():
form = model_form(Post, exclude=('created_at', 'comments'))
return render_template('home.html', form=form)
我不知道如何在模板中呈现此表单。我确实尝试了几件事:
{% for field in form %}
{{ field }}
{% endfor %}
这给出了以下错误:
TypeError: 'FormMeta' object is not iterable
我也试过这个:
{{ form.body() }}
有不同的错误:
AttributeError: 'UnboundField' object has no attribute '__call__'
和 {{ form.body }} 像这样呈现
<UnboundField(TextAreaField, (), {'default': None, 'validators': [<wtforms.validators.Required object at 0x7f63804d0fd0>], 'description': '', 'filters': [], 'label': None})>