Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

wtform custom validator example

class RegisterForm(FlaskForm):
    username = StringField(validators=[InputRequired(), Length(min=4, max=20)], render_kw={"placeholder": "Username"})
    password = PasswordField(validators=[InputRequired(), Length(min=4, max=20)], render_kw={"placeholder": "Password"})
    submit = SubmitField("Register")

    def validate_username(self, username):
        existing_username = User.query.filter_by(username=username.data).first()
        print(existing_username.username)
        if existing_username:
            raise ValidationError("Username already exists!")
 
PREVIOUS NEXT
Tagged: #wtform #custom #validator
ADD COMMENT
Topic
Name
2+3 =