def validate_username(self, field): if User.query.filter_by(username=field.data).first(): raise ValidationError('username already registered.')