flask 自定义表单验证器(flask 19)

2019-08-13 14:37:58 浏览数 (1)

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

0 人点赞