Flask EqualTo验证器,在哪里定义password2

时间:2017-03-28 14:49:25

标签: python flask

我遵循Flask Web Development的书籍,但遇到了以下代码的问题:

class RegistrationForm(Form):
    email = StringField('Email', validators=[Required(),
                        Length(1, 64), Email()])
    username = StringField('Username', validators=[Required(),
                           Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0,
                           'Usernames must have only letters, numbers,'
                                  'underscores or dots')])
    password = PasswordField('Password', validators=[Required(),
                             EqualTo(password2,
                             message="Passwords must match")])
    password2 = PasswordField('Confirm password', validators=[Required()])
    submit = SubmitField('Register')

password2之后定义password,这会导致错误:NameError: name 'password2' is not defined。这里发生了什么?我该如何定义password2

1 个答案:

答案 0 :(得分:1)

引用它

password = PasswordField('Password', validators=[Required(),
                         EqualTo('password2',
                         message="Passwords must match")])