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