基本上我在Python中有一个列表,并希望以编程方式调用并创建一个下拉表单从这个列表使用WTForms到HTML文档。当我试图在WTForms中使用SelectField方法时,我无法弄清楚我在这里缺少什么。列表在"updatef"中。
我得到错误:ValueError:需要多于一个值来解包当尝试运行这个。
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 <form id="main" action="" method="post" role="form" spellcheck="true">
<p> {{ form.updates }} </p>
choices
必须是2个值元组的列表,例如[(1,'Daily'),(2,'Weekly')]
-您的错误似乎表明您可能只有一个值列表。