使用flask_bootstrap渲染WTForms FieldList

时间:2019-05-21 17:47:00

标签: python flask flask-wtforms flask-bootstrap

我正在尝试使用flask_bootstrap渲染包含FieldList的表单。 这些是我的表单类:

forms.py

class FormEntry(FlaskForm):
    selectfield = SelectField('Name', coerce=int)

class MyForm(FlaskForm):
    form_entries = FieldList(FormField(FormEntry))

没有引导程序,此代码完美呈现了表单:

render.html

<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
{% for subfield in form.form_entries %}
    {{ subfield }}
{% endfor %}
</form>

但是,当我使用函数wtf.form_field()用boostrap渲染表单时...

{% import 'bootstrap/wtf.html' as wtf %}
...
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
{% for subfield in form.form_entries %}
    {{ wtf.form_field(subfield) }}
{% endfor %}
</form>

...我收到此错误:

{{field.label(class="control-label")|safe}}

TypeError: 'str' object is not callable

我想念什么?

0 个答案:

没有答案