I’m using virtualenv to set up a new project. I installed a lot of things using virtualenv pip from the script folder like below:
JavaScript
x
2
1
flaskscriptspip install Flask-WTF
2
I have no other packages installed in the global python folder. My code looks like this:
JavaScript
1
9
1
# Importing TextField and BooleanField is not working...
2
from flask.ext.wtf import Form, TextField, BooleanField
3
from flask.ext.wtf import Required
4
5
6
class LoginForm(Form):
7
openid = TextField('openid', validators=[Required()])
8
remember_me = BooleanField('remember_me', default=False)
9
and other packages are found like sqlalchemy also installed only in the virtual environment.
The error I get is:
JavaScript
1
7
1
(flask) D:Developmentgrading>flaskScriptspython.exe restserver.py Traceback (most recent call last):
2
File "restserver.py", line 1, in <module> from app import app
3
File "D:Developmentgradingapp__init__.py", line 12, in <module> from forms import LoginForm
4
File "D:Developmentgradingappforms.py", line 1, in <module> from flask.ext.wtf import Form, TextField, BooleanField
5
File "D:Developmentgradingflasklibsite-packagesflaskexthook.py", line 87, in load_module
6
raise ImportError('No module named %s' % fullname) ImportError: No module named flask.ext.wtf.TextField
7
Form is found but not TextField and BooleanField. What is the problem here?
Update I just looked through some of the Flask-WTF code and found this:
JavaScript
1
4
1
from flask.ext.wtf import Form
2
from wtforms.fields import TextField, BooleanField
3
from wtforms.validators import Required
4
Am I using examples from an older version or something?
Advertisement
Answer
From version 0.9.0, Flask-WTF will not import anything from wtforms, you need to import fields from wtforms.
You need to import them from wtforms
(note that according to docs
import statement was changed):
JavaScript
1
5
1
from flask_wtf import Form
2
3
from wtforms import TextField, BooleanField
4
from wtforms.validators import Required
5