Attributeerror: 'editform' Object Has No Attribute 'validate_on_submit'
Solution 1:
You imported the wrong Form
object:
from flask.ext.wtf import Formfrom wtforms import Form, TextField, BooleanField, PasswordField, TextAreaField, validators
The second import line imports Form
from wtforms
, replacing the import from flask_wtf
. Remove Form
from the second import line (and update your flask.ext.wtf
import to flask_wtf
to remain future-proof):
from flask_wtf importFormfrom wtforms importTextField, BooleanField, PasswordField, TextAreaField, validators
Two additional notes:
The form will take values from the request for you, no need to pass in
request.form
.validate_on_submit()
tests for the request method too, no need to do so yourself.
The following then is enough:
@app.route('/edit', methods = ['GET', 'POST'])defedit():
form = EditForm()
if form.validate_on_submit():
And as of Flask-WTF version 0.13 (released 2016/09/29), the correct object to use is named FlaskForm
, to make it easier to distinguish between it and the wtforms
Form
class:
from flask_wtf importFlaskForm
Solution 2:
When creating the form, you must be sure you added class EditForm(FlaskForm)
to your class:
That is where my bug was coming from.
Post a Comment for "Attributeerror: 'editform' Object Has No Attribute 'validate_on_submit'"