form.validate_on_submit()错误unboundField

时间:2018-10-29 21:09:54

标签: validation flask flask-wtforms

使用form.validate_on_submit()时出现错误,显示

  

`UnboundField'对象不可调用

@app.route('/register', methods=['GET', 'POST'])
def register():
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
            flash({form.username.data}, 'success')
            return 'i did it'

forms.py

class RegistrationForm(FlaskForm):
    username = StringField('Username',
                           validators=[DataRequired(), Length(min=2, max=15)])
    email = StringField('Email ',
                        validators=[DataRequired(), Email()])
    password = PasswordField('Password',
                             validators=[DataRequired()])
    # confirm_password = PasswordField('confirm_password',
    #                                  validators=[DataRequired(), EqualTo('password')])
    submit = SubmitField('SignUp', validators=[])

0 个答案:

没有答案