0
我在form.py瓶選擇場 - 不是有效的選擇
OPTIONS = ['Option1', 'Option2', 'Option3']
class Test_Form(Form):
test = SelectField('Dropdown', coerce= str,
choices=[(f, f) for f in OPTIONS])
submit = SubmitField('Submit')
下面的代碼和下面的代碼在我的模板
<div class = "control-group">
<label class="control-label">
{{ form.test.label }} </label>
{% if form.test.errors %}
{% for error in form.test.errors %}
<p class="error-message"> {{ error }}</p>
{% endfor %}
{% endif %}
<div class="controls">
<select name=form.test.label width="80px">
{% for i,j in form.test.choices %}
<option value = {{ i }} > {{ j }} </option>
{% endfor %}
</select>
</div>
</div>
以下是我的看法功能
def show_logs():
my_form = Test_Form()
if request.method == "POST":
if logs_form.validate() == False:
return render_template('test.html', form = my_form)
else:
return my_form.test.data
#return render_template('test_success.html', output = output_list)
elif request.method == "GET":
return render_template('test.html', form = my_form)
我每次提交表單時都會收到「不合理的選擇」。我經歷了以上關於SO的所有問題,並嘗試了coerce = str
,但我仍然收到相同的信息。我在這裏錯過了什麼?