Python 烧瓶表单验证错误提示消息

Python 烧瓶表单验证错误提示消息,python,flask,Python,Flask,我制作了一个表单来重置密码,当我用空密码提交表单时,我在views.py中设置的错误提示词没有显示在我在HTML中留下的处,而是显示了一个默认的填写此字段 *第一个是旧密码,第二个是新密码 在forms.py中: class PwdForm(FlaskForm): old_pwd = PasswordField( label="OldPassword", validators=[ DataRequired("Please input

我制作了一个表单来重置密码,当我用空密码提交表单时,我在
views.py
中设置的错误提示词没有显示在我在HTML中留下的
处,而是显示了一个默认的
填写此字段

*第一个是旧密码,第二个是新密码 在forms.py中:

class PwdForm(FlaskForm):
    old_pwd = PasswordField(
        label="OldPassword",
        validators=[
            DataRequired("Please input old password")
        ]
    )
    submit = SubmitField(
        "Confirm"
    )
在views.py中:

@admin.route("/pwd_reset/", methods=["GET", "POST"])
@admin_login_req
def pwd_reset():
    form = PwdForm()
    if form.validate_on_submit():
        data = form.data
        admin = Admin.query.filter_by(name=session["admin"]).first()
        from werkzeug.security import generate_password_hash
        admin.pwd = generate_password_hash(data["new_pwd"])
        db.session.add(admin)
        db.session.commit()
        flash("ok, now use your new password to login", "ok")
        redirect(url_for("admin.logout"))
    return render_template("admin/pwd_reset.html", form=form)
在html中:

<label for="input_pwd">{{ form.old_pwd.label }}</label>
{{ form.old_pwd }}
{% for err in form.old_pwd.errors %}
<span style="color: #ff4f1f">{{ err }}</span>
{% endfor %}
{{form.old_pwd.label}
{{form.old_pwd}
{form.old_pwd.errors%}
{{err}}
{%endfor%}

如何显示我自己的提示信息

我想你的意思是如何显示你的flash信息?在基本模板页面或每个页面中使用以下代码。见:

{%with messages=get\u flashed\u messages()%}
{%if消息%}
    {消息%中的消息为%s}
  • {{message}}
  • {%endfor%}
{%endif%} {%endwith%}
您的问题不清楚,是否希望在用户未提供旧密码时,您的表单中显示消息
请输入旧密码
,或者问题到底是什么?
{% with messages = get_flashed_messages() %}
  {% if messages %}
    <ul class="flashes">
    {% for message in messages %}
      <li>{{ message }}</li>
    {% endfor %}
    </ul>
  {% endif %}
{% endwith %}