列表转换为Flask/WTForms中的下拉列表

2024-06-16 13:22:27 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,我在Python中有一个列表,我想通过编程方式调用并使用WTForms在HTML文档中创建一个下拉表单。当尝试在WTForms中使用SelectField方法时,我不知道我在这里遗漏了什么。列表在“updatef”中。在

我得到错误:值错误:需要多于1个值才能解压缩 当尝试运行这个。在

class ReusableForm(Form):  # Define the form fields and validation parameters
    updates = SelectField(u'Update Frequency', choices = updatef, validators = [validators.required()])


@app.route("/editor", methods=['GET', 'POST'])
def hello():
    form = ReusableForm(request.form)  # calls on form

        if request.method == 'POST':
            updates = request.form['updates']

HTML格式

^{pr2}$

Tags: 文档form列表requesthtml编程错误方式
1条回答
网友
1楼 · 发布于 2024-06-16 13:22:27

choices必须是2个值元组的列表,例如[(1,'Daily'),(2,'Weekly')]-您的错误似乎表明您可能只有一个值列表。在

相关问题 更多 >