Importing flask.ext.wtf

I am using venv, and I develop using eclipse . I want to add a contact page .

I did :

$ . bin/activate
$ pip install flask-wtf

And I import some modules in the forms.py :

I used this :

from flask.ext.wtf import Form, TextField, TextAreaField, SubmitField

and then this :

from flask.ext.wtf import Form
from wtforms.fields import TextField, BooleanField

No one of them worked because I had this error :

from flask.ext.wtf import Form
  File "/usr/local/lib/python2.7/dist-packages/flask/exthook.py", line 87, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.wtf

Answers


What version of flask-wtf did you install? Since version 9 you do all of the field imports from WTForms not from Flask-WTF.

So your imports will be (note that according to docs import statement was changed):

from flask_wtf import Form
from wtforms import TextField, BooleanField

I solved this by using venv/bin/pip install flask-wtf instead of pip install flask-wtf (even if I activated venv before the second command . bin/activate )


I had to use

from flask_wtf import Form

instead of

from flask.ext.wtf import Form

Even after changing different import styles and re-installing flask, flask-wtf, if it still does not works : then in the config.py( "config.py may be of different name eg app_config.py etc)

insert the line

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'venv/Lib/site-packages'))

set the lib path of your own app , in my case it was "venv/Lib/site-packages"


Need Your Help

Decoding sniffed packets

security decoding sniffing

I understand that each packet has some header that seems like a random mix of chars. On the other hand, the content itself can be in pure ascii and therefore it might be human friendly. Some of the

How to change a background color of jQueryUI Progressbar?

jquery-ui background progress-bar

How to change a background color of jQueryUI Progressbar?