From flask. ext. wtf import Form import error,

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.