【发布时间】:2014-10-09 01:16:24
【问题描述】:
我正在学习 http://code.tutsplus.com/tutorials/intro-to-flask-adding-a-contact-page--net-28982 的 Flask 教程,目前卡在验证步骤中:
旧版本有以下内容:
from flask.ext.wtf import Form, TextField, TextAreaField, SubmitField, validators, ValidationError
class ContactForm(Form):
name = TextField("Name", [validators.Required("Please enter your name.")])
email = TextField("Email", [validators.Required("Please enter your email address."), validators.Email("Please enter your email address.")])
submit = SubmitField("Send")
阅读 cmets 我将其更新为:(将验证器替换为 InputRequired)
(same fields)
class ContactForm(Form):
name = TextField("Name", validators=[InputRequired('Please enter your name.')])
email = EmailField("Email", validators=[InputRequired("Please enter your email address.")]), validators.Email("Please enter your email address.")])
submit = SubmitField("Send")
我唯一的问题是我不知道如何处理validators.Email。我得到的错误信息是:
NameError: name 'validators' is not defined
我查看了文档,也许我没有深入研究,但我似乎找不到电子邮件验证的示例。
【问题讨论】:
标签: python validation email flask-wtforms