0
基本上我在Python中有一个列表,并且希望以编程方式调用并使用WTForms从这个列表创建一个下拉列表到HTML文档中。在WTForms中尝试使用SelectField方法时,我无法弄清楚我在这里丢失了什么。该列表在“updatef”内。列表转换为Flask/WTForms中的下拉列表
我得到的错误: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>
嗯谢谢!我会看看明天,但这是有道理的。 – Infinity8
谢谢你这样做。我只需要将“id”主键添加到列表中。 – Infinity8
所以我只能通过为SelectField参数添加coerce = int来获得这个工作。但输出是选择的“ID”号码。所以例如我的第二个选择是“BOB”,但是我的输出是ID号“2”。我将如何获得“BOB”作为我的输出? – Infinity8