From flask. ext. wtf import Form import error,
Source:
Learn Flask online tutorials (PS: Link to the Chinese version tutorial. The code in the English version of the tutorial is correct, and there is no running error. I want to see it faster, so I can directly read the Chinese version> ~ <, English tutorial link), use the following code:
from flask.ext.wtf import Formfrom wtforms import StringField, BooleanFieldfrom wtforms.validators import DataRequiredclass LoginForm(Form): openid = StringField('openid', validators=[DataRequired()]) remember_me = BooleanField('remember_me', default=False)
As a result, an error is reported when the red part is marked above, indicating that the Form class cannot be referenced.
So I checked the Quick Start example described in detail in flask-WTF. The code for using Flask-WTF is as follows:
from flask_wtf import Formfrom wtforms import TextFieldfrom wtforms.validators import DataRequiredclass MyForm(Form): name = TextField('name', validators=[DataRequired()])
Since version 0.9.0, Flask-WTF no longer imports anything from WTforms. You need to import fields from WTForms.
Solution: change from flask. ext. wtf import Form to from flask_wtf import Form.
Specific cause: I think it is caused by the Flask-wtf version.