如题给message设置了提示 但不显示
这个是表单类:
from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,BooleanField,SubmitField
from wtforms.validators import DataRequired,Length
class BaseForm(FlaskForm):
username = StringField(“用户名”,validators=[DataRequired(message=“用户名必须在8到20位之间”),Length(8,20)])
password = PasswordField(“密码”,validators=[DataRequired(message=“密码必须在8到20位之间”),Length(8,20)])
login = SubmitField(“登录”)
这个是宏
{% macro baseForm(func) %}
{{ func.label }}
{{ func(**kwargs) }}
{% if func.errors %}
{% for error in func.errors %}
<small class=“errors”>{{ error }}</small>
{% endfor %}
{% endif %}
<br>
{% endmacro %}
这个是渲染表单的代码
{% block body %}
<form action=“{{ url_for(“login”) }}” method=“post”>
{{ login_form.csrf_token }}
{{ baseForm(login_form.username) }}
{{ baseForm(login_form.password) }}
{{ baseForm(login_form.login) }}
</form>
{% endblock %}
这个是视图函数
@app.route(“/login”,methods=[“GET”,“POST”])
def login():
login_form = BaseForm()
if login_form.validate_on_submit():
username = login_form.username.data
password = login_form.password.data
flash(“你的用户名是{},密码是{}”.format(username,password))
return redirect(url_for(“index”))
return render_template(“login.html”, login_form=login_form)这个是最后的前端页面