如何在Jinja2模板里面渲染WTForm的FieldList表单字段?



 class GuestForm(Form):
email = TextField()
vip = BooleanField()

class VenueForm(Form):
    name = TextField()
    bio  = TextField()
    guests = FieldList(FormField(GuestForm))

==============================================


 class TelephoneForm(Form):
    country_code = IntegerField('Country Code', [validators.required()])
    area_code    = IntegerField('Area Code/Exchange', [validators.required()])
    number       = TextField('Number')

class ContactForm(Form):
    first_name   = TextField()
    last_name    = TextField()
    mobile_phone = FormField(TelephoneForm)
    office_phone = FormField(TelephoneForm)
    phones       = FieldList(FormField(TelephoneForm))

wtforms

chrls 11 years, 9 months ago

可以使用Bootstrap自带的一系列表单样式。Flask-Bootstrap使用Bootstrap的预定义表单样式来提供高级的帮助函数来渲染整个Flask-WTF表单,这些操作都只需要一个调用即可完成。


 {% import "bootstrap/wtf.html" as wtf %}
{{ wtf.quick_form(form) }}

可以参考一下这篇文章: Flask Web Development —— Web表单

黑暗的小白 answered 10 years, 3 months ago

Your Answer