from flask_babel import lazy_gettext as _ from flask_wtf import FlaskForm from wtforms import PasswordField, StringField from wtforms.validators import DataRequired, Email, ValidationError class RegistrationForm(FlaskForm): username = StringField(_('Username'), validators=[DataRequired()]) email = StringField(_('Email address'), validators=[Email()]) password = PasswordField(_('Password'), validators=[DataRequired()]) password_retype = PasswordField(_('Password, once more'), validators=[DataRequired()]) def validate_password_retype(self, field): if field.data != self.password.data: raise ValidationError(_('The two passwords must match!'))