form中关于表单的定义
class AreaListForm(Form): area1 = BooleanField(u‘1区‘, default=False) area2 = BooleanField(u‘2区‘, default=False) area3 = BooleanField(u‘3区‘, default=False) area4 = BooleanField(u‘4区‘, default=False) area5 = BooleanField(u‘5区‘, default=False) area6 = BooleanField(u‘6区‘, default=False) area7 = BooleanField(u‘7区‘, default=False) area8 = BooleanField(u‘8区‘, default=False) area9 = BooleanField(u‘9区‘, default=False) class Good_retainForm(AreaListForm): user_account = StringField(u‘用户账号‘, validators=[DataRequired()]) submit = SubmitField(u‘查询‘)
视图函数中的定义
@main.route(‘/goods_retain‘, methods=[‘GET‘, ‘POST‘]) @login_required def goods_retain(): form = Good_retainForm() return render_template(‘goods_retain.html‘, form=form)
模板中的宏定义
{% macro area_form(form) %} {{ form.area1 }} {{ form.area1.label }} {{ form.area2 }} {{ form.area2.label }} {{ form.area3 }} {{ form.area3.label }} {{ form.area4 }} {{ form.area4.label }} {{ form.area5 }} {{ form.area5.label }} {{ form.area6 }} {{ form.area6.label }} {{ form.area7 }} {{ form.area7.label }} {{ form.area8 }} {{ form.area8.label }} {{ form.area9 }} {{ form.area9.label }} {% endmacro %}
模板中引用宏
{% from "_area_marco.html" import area_form %} {{ area_form(form) }}
时间: 2024-10-10 18:25:00