我遵循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
?
答案 0 :(得分:1)
引用它
password = PasswordField('Password', validators=[Required(),
EqualTo('password2',
message="Passwords must match")])