Email Validation from WTForm using Flask
Posted
by
lost9123193
on Stack Overflow
See other posts from Stack Overflow
or by lost9123193
Published on 2014-08-15T09:25:43Z
Indexed on
2014/08/22
4:20 UTC
Read the original article
Hit count: 597
I'm following a Flask tutorial from http://code.tutsplus.com/tutorials/intro-to-flask-adding-a-contact-page--net-28982 and am currently stuck on the validation step:
The old version had the following:
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")
Reading the comments I updated it to this: (replaced validators.Required with 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")
My only issue is I don't know what to do with the validators.Email. The error message I get is:
NameError: name 'validators' is not defined
I've looked over the documentation, perhaps I didn't delve deep enough but I can't seem to find an example for email validation.
© Stack Overflow or respective owner