我有一个动态表格:
class CollectionRequestParamForm(Form):
param_human_name = StringField(validators=[DataRequired()])
param_request_name = StringField()
class CollectionRequestParamCombinedForm(FlaskForm):
params = FieldList(FormField(CollectionRequestParamForm), min_entries=2)
submit = SubmitField('Submit')
我想在视图中设置min_entries
,例如:
collection_request_params_form = CollectionRequestParamCombinedForm(min_entries=5)
我这样做:
class CollectionRequestParamCombinedForm(FlaskForm):
def __init__(self, min_entries, *args, **kwargs):
FlaskForm.__init__(self, *args, **kwargs)
self.params = FieldList(FormField(CollectionRequestParamForm), min_entries=min_entries)
submit = SubmitField('Submit')
但是:TypeError: 'UnboundField' object is not iterable
导致此错误的原因是什么?
答案 0 :(得分:0)
如果要使其动态化,请执行此操作
for i in range(min_entries):
form.params.append_entry()