我的表单中有一个SelectField
,该文件是从发生在我的路线中的文件上传动态填充的。该路线的摘要位于下方,我的整个表单也位于下方。因此,行为是用户读取数据文件,然后使用该文件中的信息填充SelectField
选择。这样就可以了。
动态填充SelectField
可以在我的应用程序中很好地工作,但是我需要更新它以允许多个选择而不是一个选择。因此,我已将此SelectMultipleField
添加到表单中,并尝试使用与SelectField
相同的概念来动态更新。我假设关于这两者之间的参数和输入的行为是相似的,但也许是错误的。
在这种情况下,它不起作用,并且出现错误TypeError: 'NoneType' object is not iterable
。以下是我路线中的部分代码:
vars = list(tab3.TestName.unique())
form2.test2use.choices = vars # note, this works as expected
form2.testing.choices = vars # just a test
下面是表格
class config_reports(FlaskForm):
test2use = SelectField('Choose a test', [DataRequired()], coerce=str)
#testing = SelectMultipleField('Multiple Options Should Appear Here', [DataRequired()], choices=[('A1', 'A1'), ('B1', 'B1'), ('C1', 'C1')])
testing = SelectMultipleField('Multiple Options Should Appear Here', [DataRequired()], coerce=str)
submit = SubmitField('Run Report')
如果我取消注释硬编码的#testing
并用选项填充它,然后在读取文件时尝试动态更改它们,则会出现ValueError: too many values to unpack (expected 2)
的错误
是否有关于如何动态填充SelectMultipleField
而不是SelectField
的建议?