form.py
from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, BooleanField, IntegerField, TextAreaField, SubmitField, MultipleFileField from wtforms.validators import DataRequired, Length, ValidationError, Email
custom validator
class FortyTwoForm(FlaskForm): answer = IntegerField('The Number') submit = SubmitField()
代码语言:javascript复制def validate_answer(form, field):
if field.data != 42:
raise ValidationError('Must be 42.')
自定义全局验证器
image.png