两种方法
github资源
我没验证过
注意, 这样子写不如前端修改灵活
class OneStuForm(FlaskForm):
name = StringField('姓名', validators=[DataRequired()])
stunum = StringField('学号',validators=[DataRequired(), Length(6,6)] )
phone = StringField('手机号',validators=[DataRequired(),Length(11,11)])
email = StringField('电子邮箱地址', validators=[
DataRequired(), Length(1, 64), Email()])
college = StringField('学院', validators=[DataRequired()])
major = StringField('专业', validators=[DataRequired()])
def signupcompetition():
members = 2
class LocalForm(FlaskForm): pass
for i in range(0, members):
if i==0:
setattr(LocalForm, '组长',FormField(OneStuForm, label='组长'))
else:
setattr(LocalForm, '组员'+str(i), FormField(OneStuForm,label='组员'+str(i)))
LocalForm.submit = SubmitField('提交报名信息')
form = LocalForm()
return render_template('competitionregister.html', form=form)