在py文件中:
class form(flaskform):
form1 = DecimalField("00:00", validators=[InputRequired()])
form2 = DecimalField("00:10", validators=[InputRequired()])
.
.
.
form50 = DecimalField("00.xx, validators=[InputRequired()])
有没有办法简化这一过程?如果我想要100个表格,我不想写100行代码。
答案 0 :(得分:1)
def Form(n=100):
class TempForm(FlaskForm):
pass
for i in range(n):
setattr(TempForm, 'form{}'.format(i+1),
DecimalField('00.{}'.format(i*10), validators=
[InputRequired()])
return TempForm()