【发布时间】:2012-10-02 18:28:13
【问题描述】:
我正在尝试根据本文档http://wtforms.simplecodes.com/docs/1.0.2/specific_problems.html#dynamic-form-composition在具有动态字段的 WTForms 中生成一个表单
我有这个子表单类,它允许用户从列表中选择要购买的物品:
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 中实现这一点?
【问题讨论】:
-
您能否发布更多关于您使用
fld所做的代码?理想情况下,它将是 Form 类的属性,如文档中的示例:wtforms.simplecodes.com/docs/1.0.2/…