如何安装WTForms?尝试导入表单时出现导入错误

时间:2013-12-19 10:04:38

标签: python flask pip wtforms flask-wtforms

我正在尝试遵循我需要使用WTForms的Flask Mega Tutorial。正如教程中所建议的那样,我使用virtualenv,我在其中安装了WTForms:

flask/bin/pip install flask-wtf

这似乎工作正常,当我现在再次运行时,我只是得到了这个:

Requirement already satisfied (use --upgrade to upgrade): flask-wtf in ./flask/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): Flask in ./flask/lib/python2.7/site-packages (from flask-wtf)
Requirement already satisfied (use --upgrade to upgrade): WTForms>=1.0 in ./flask/lib/python2.7/site-packages (from flask-wtf)
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in ./flask/lib/python2.7/site-packages (from Flask->flask-wtf)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in ./flask/lib/python2.7/site-packages (from Flask->flask-wtf)
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in ./flask/lib/python2.7/site-packages (from Flask->flask-wtf)
Requirement already satisfied (use --upgrade to upgrade): markupsafe in ./flask/lib/python2.7/site-packages (from Jinja2>=2.4->Flask->flask-wtf)
Cleaning up...

但是当我尝试使用from forms import LoginForm导入表单时,我收到错误消息:ImportError: cannot import name LoginForm

有人知道我在这里做错了什么,以及如何解决这个问题?欢迎所有提示!

1 个答案:

答案 0 :(得分:4)

您需要一个名为forms的模块,其中包含LoginForm

from flask.ext.wtf import Form
from wtforms import TextField, BooleanField
from wtforms.validators import Required

class LoginForm(Form):
    openid = TextField('openid', validators = [Required()])
    remember_me = BooleanField('remember_me', default = False)

这是取自Part iii的例子。