尝试使用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>
warehouse_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)
提交表格&#34; print form.data&#34;没有任何回报......
我无法弄清楚我错过了
答案 0 :(得分:1)
我将验证作为项目字段的参数。
class WarehouseTicketForm(Form):
spot_id = SelectField(u'Spot', coerce=int)
items = FieldList(FormField(WarehouseTicketItemForm), min_entries = 3, validators=[Required()])