我正在尝试使用 WTForms 生成一个具有动态字段的表单,根据这份文档:http://wtforms.simplecodes.com/docs/1.0.2/specific_problems.html#dynamic-form-composition
我有一个子表单类,允许用户从列表中选择要购买的物品:
class Item(Form):
itmid = SelectField('Item ID')
qty = IntegerField('Quantity')
class F(Form):
pass
将会有多个购物项类别,因此我希望根据用户选择的类别生成动态选择字段:
fld = FieldList(FormField(Item))
fld.append_entry()
但是我得到了以下错误:
AttributeError: 'UnboundField' object has no attribute 'append_entry'
我是在使用WTForms的过程中出了问题,还是说无法用WTForms实现这个功能?
fld
的代码吗?最好是像文档中的示例那样,作为Form类的一个属性:http://wtforms.simplecodes.com/docs/1.0.2/fields.html#wtforms.fields.FieldList - aezell