我希望动态使用min_entries WTForms参数,即不使用硬编码数字。在
它看起来像这样表单.py公司名称:
class TestSpecForm(FlaskForm):
student_number = IntegerField('Number of Students')
class StudentForm(FlaskForm):
answer = StringField('')
class TestInputForm(FlaskForm):
students = FieldList(FormField(StudentForm)) # I'd like to insert the dynamic min_entries here
submit = SubmitField('Submit')
像这样的东西视图.py公司名称:
^{pr2}$但是,这不起作用,只是没有为TestInputForm呈现字段。如果我在TestInputForm的students变量中输入“min_entries=10”,那么一切都按预期工作。但我不能动态完成。在
谁能帮帮我吗?根据我所有的google/reddit/SO搜索,这基本上就是WTForms中大多数参数或验证器的动态设置方式。在
谢谢你
不可能动态重写
FieldList
上的min_entries
。在解决方法是将窗体子类化并用所需的值绑定一个新的
FieldList
。在所以你的代码应该是这样的:
相关问题 更多 >
编程相关推荐