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

我试图使用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)

提交表单“print form.data”不会返回任何内容……

我无法弄清楚我失踪了

最佳答案 我会将验证作为items字段的参数.

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