Flask 烧瓶+;WTForms-在FormList中显示字段
我正在尝试构建一个带有动态字段的表单(单击加号添加额外字段) forms.py:Flask 烧瓶+;WTForms-在FormList中显示字段,flask,jinja2,wtforms,flask-wtforms,Flask,Jinja2,Wtforms,Flask Wtforms,我正在尝试构建一个带有动态字段的表单(单击加号添加额外字段) forms.py: class ActionForm(Form): key = SelectField("Type: ", coerce=int, choices=[(0, "Option 1"), (1, "Option 2"), (2, "Opeion 3")], default=0) value = StringField('Value: ') class EditForm(Form): conten
class ActionForm(Form):
key = SelectField("Type: ", coerce=int, choices=[(0, "Option 1"), (1, "Option 2"), (2, "Opeion 3")], default=0)
value = StringField('Value: ')
class EditForm(Form):
content = StringField("Content: ")
actions = FieldList(FormField(ActionForm))
status = RadioField("Status: ", coerce=int, choices=[(0, "Inactive"), (1, "Active")], default=1)
submit = SubmitField("Submit")
视图模板(不会呈现ActionForm中的字段):
<form method="POST">
{{ form.csrf_token }}
{{ form.actions.label }}
<div class="form-group input-group">
{% for action in form.actions %}
{% for field in action %}
{{ field() }}
{% endfor %}
{% endfor %}
</div>
{{ form.status.label }}{{ form.status }}
{{ form.submit() }}
</form>
{{form.csrf_token}
{{form.actions.label}
{%用于表单中的操作。操作%}
{%用于操作中的字段%}
{{field()}}
{%endfor%}
{%endfor%}
{{form.status.label}{{form.status}}
{{form.submit()}}
问题:
在我的表单中,我只看到一个空白点,ActionForm
字段应该出现在这里
换句话说,我不能遍历form.actions
(以显示SelectField()和StringField()
我做错了什么?采用minu entries
关键字参数-如果设置它,它将确保至少有n个
条目:
class EditForm(Form):
content = StringField("Content: ")
actions = FieldList(FormField(ActionForm), min_entries=1)
哪里有render()命令?@AndrewKloos:在我的视图函数中。我可以让表单显示(例如,状态显示),但
字段列表
ed字段不显示。我基本上只是尝试支持这个引导多字段元素:。