正如标题所说,这就是我所拥有的:
form = F(obj = myobject)
myfieldlist= FieldList(FormField(form))
{% for subfield in form.myfieldlist %}
{{ subfield.field }}
{{ subfield.label }}
{% endfor %}
这什么也没输出,有什么想法吗?此外,不完全确定是否需要 FormField。谢谢
FormField
接受一个类而不是一个实例:
class GuestForm(Form):
email = TextField()
vip = BooleanField()
class VenueForm(Form):
name = TextField()
guests = FieldList(FormField(GuestForm))
然后在你的控制器中:
form = VenueForm(obj=myobject)
render("template-name.html", form=form)
在您的模板中,您将需要遍历 FieldList 字段,就好像它是它自己的表单一样:
{% for guest_form in form.guests %}
<ul>
{% for subfield in guest_form %}
<li>{{ subfield.label }} {{ subfield }}</li>
{% endfor %}
</ul>
{% endfor %}