我在Flask应用程序的许多页面中使用QuerySelectField,它运行正常。除了在一条路线中,当我提交表格时,我不断收到“不是有效选择”的信息。
然而,正确填充了下拉菜单,并确实在其中选择了一个选项。当我打印()字段数据时,我得到一个“无”,所以似乎有问题,因为即使我们选择一个选项,表单似乎传递“无”作为结果。知道为什么吗?
该字段设置为:
buy_pc = QuerySelectField('Punch-cards',query_factory=getPunchcards,get_label='label')
以下是完整表格:
def getPunchcards():
return Punchcard.query
class Add_participants(Form):
member_name = StringField('Type the tribe\'s member full name:', validators=[DataRequired()])
choice = RadioField('Registration mode',validators=[DataRequired()],choices=[('season_pass','Season Pass'),
('punchcard', 'Punch-card'),
('free_pass','Using a free pass'),
('old_punchcard','Using old punch-card'),
('dropin','Drop-in'),
('checked','Use another member punch-card')])
dropin_ammount = IntegerField('Drop-in ammount',validators=[NumberRange(min=0,max=25,message='Please '
'enter an amount btw 0 and 25')],default=10)
add_note = BooleanField('Add a note to the member profile')
note_content = TextAreaField()
other_punchcard = StringField('Type the tribe\'s member full name:')
buy_pc = QuerySelectField('Punch-cards',query_factory=getPunchcards,get_label='label')
submit = SubmitField('Add')