I have a small edit app with the files bellow. When I submit tbe form it shows me AttributeError: \'EditForm\' object has no attribute \'validate_on_submit\' Ca
You imported the wrong Form
object:
from flask.ext.wtf import Form
from 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 import Form
from wtforms import TextField, 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'])
def edit():
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 import FlaskForm