gpt4 book ai didi

flask - WTF 表单(Flask)- FormField - FieldList,验证不起作用

转载 作者:行者123 更新时间:2023-12-03 15:54:28 33 4
gpt4 key购买 nike

我正在尝试使用 WTF 字段、FormField、FieldList 创建一个 ListItem 表单:

forms.py

class WarehouseTicketItemForm(Form):
description = StringField(u'Description', validators=[Required()])
quantity = IntegerField(u'Quantity', validators=[Required()])

class WarehouseTicketForm(Form):
spot_id = SelectField(u'Spot', coerce=int)
items = FieldList(FormField(WarehouseTicketItemForm), min_entries = 3)

warehouse_ticket_form.html
<form action="" method='POST'>
{{ form.hidden_tag() }}
{{ form.spot_id }} <br>
{% for item in form.items %}
{{ item }}
{% endfor %}
<button type="submit" name="button">Save it</button>

仓库_tickets.py
@coordinator.route('/warehouses/tickets/update', methods=['GET', 'POST'])
def update_warehouses_tickets():
page = dict(title="Warehouse Ticket")
form = WarehouseTicketForm()
form.spot_id.choices = [(s.id, s.name)
for s in Spot.query.filter_by(status=True)]
if form.validate_on_submit():
print form.data
return render_template('coordinators/warehouses/warehouse_ticket_form.html',
page=page, form=form)

提交表单“print form.data”不会返回任何东西......

我不知道我失踪了

最佳答案

我会将验证作为 items 字段的参数。

class WarehouseTicketForm(Form):
spot_id = SelectField(u'Spot', coerce=int)
items = FieldList(FormField(WarehouseTicketItemForm), min_entries = 3, validators=[Required()])

关于flask - WTF 表单(Flask)- FormField - FieldList,验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35790861/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com