当我尝试在我的应用程序中添加SelectField时,它将停止应用程序的提交功能,也将停止显示验证警告。当我在添加SelectField之后按下提交按钮时,没有POST请求发送到终端。可能是什么原因造成的?
这里是我的表格:
class AssessForm(FlaskForm):
date = DateTimeField(label='Review Date', validators=[DataRequired()], default=datetime.now())
textfield1 = TextAreaField(label='TextField1', validators=[DataRequired()])
textfield2 = TextAreaField(label='TextField2')
priority = SelectField(label='Priority', choices=[('low', 'low'), ('medium', 'medium'), ('high', 'high')])
submit = SubmitField('Submit')
和html:
<form method="POST" action="">
{{ form.hidden_tag() }}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Join Today</legend>
<div class="form-group">
{{ form.date.label(class="form-control-label") }}
{% if form.date.errors %}
{{ form.date(class="form-control form-control-lg is-invalid") }}
<div class="invalid-feedback">
{% for error in form.date.errors %}
<span>{{ error }}</span>
{% endfor %}
</div>
{% else %}
{{ form.date(class="form-control form-control-lg") }}
{% endif %}
</div>
<div class="form-group">
{{ form.textfield1.label(class="form-control-label") }}
{% if form.textfield1.errors %}
{{ form.textfield1(class="form-control form-control-lg is-invalid") }}
<div class="invalid-feedback">
{% for error in form.textfield1.errors %}
<span>{{ error }}</span>
{% endfor %}
</div>
{% else %}
{{ form.textfield1(class="form-control form-control-lg") }}
{% endif %}
</div>
<div class="form-group">
{{ form.textfield2.label(class="form-control-label") }}
{% if form.textfield2.errors %}
{{ form.textfield2(class="form-control form-control-lg is-invalid") }}
<div class="invalid-feedback">
{% for error in form.textfield2.errors %}
<span>{{ error }}</span>
{% endfor %}
</div>
{% else %}
{{ form.textfield2(class="form-control form-control-lg") }}
{% endif %}
</div>
<div class="form-group">
{{ form.priority.label(class="form-control-label") }}
<form action="" method="post" name="AssessForm">
{{form.hidden_tag()}}
<p>
{{form.priority(size=1)}}
</p>
</form>
</div>
</fieldset>
<div class="form-group">
{{ form.submit(class="btn btn-outline-info") }}
</div>
</form>
如果我删除优先级部分,该表格将按预期工作。