在这个脚本中,我将wtforms.validator
中InputRequired
的消息设置为显示错误。另外,我给出了字符长度的max和min。但这些论点并不奏效
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, IntegerField, SubmitField,StringField
from wtforms.validators import ValidationError, Length, EqualTo, InputRequired, Email
class Login(FlaskForm):
email =StringField(validators=[InputRequired(message = 'please input something'), Length(min=10, max=20), Email(message='this is not email')])
password = PasswordField(validators=[InputRequired(message='please input something'), Length(min=8, max=20, message='you must be input more than 8 character')])
submit = SubmitField('Enter')
class Register(FlaskForm):
email =StringField(validators=[InputRequired(message = 'please input something'), Length(min=10, max=20), Email(message='this is not email')])
phone = IntegerField(validators=[InputRequired(message='please input something')])
password = PasswordField(validators=[InputRequired(message='please input something'), Length(min=8, max=20, message='you must be input more than 8 character')])
submit = SubmitField('Enter')
这个脚本是login.html
{% extends "base.html" %}
{% block content %}
<h3>this is Home page</h3>
<form action="#">
<!-- {{forlogin.hidden_tag()}} -->
{{forlogin.email(placeholder="email")}}
<br>
{{forlogin.password(placeholder="password")}}
<br>
{{forlogin.submit}}
</form>
{% endblock content %}
从WTForms文档中的字段类文档:
因此,要显示错误,您必须在页面上显示列表中的项目:
我不知道
for
在两个大括号之间意味着什么,我把它去掉了。它导致了金甲2的错误相关问题 更多 >
编程相关推荐