Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAbdirahman Mohamed
84 PointsValidation
Validation works; however, messages don't show. By messages I mean "This field is required invalid email"... etc. Here is my forms code. Btw im doing it in Pycharm :)
from flask_wtf import Form
from wtforms import StringField,PasswordField
from wtforms.validators import DataRequired,Regexp,ValidationError, Email,Length,EqualTo
from models import User
def name_exists(form,field):
if User.select().where(User.username==field.data).exists():
raise ValidationError('User with that name already exists.')
def email_exists(form,field):
if User.select().where(User.email==field.data).exists():
raise ValidationError('User with that email already exists.')
class RegisterForm(Form):
username = StringField(
'Username',
validators=[
DataRequired(),
Regexp(
r'^[a-zA-Z0-9_]+$',
message= ("Username should be one word, "
"numbers, and underscores only.")
),
name_exists
])
email= StringField(
'Email',
validators=[
DataRequired(),
Email(),
email_exists
])
password = PasswordField(
'Password',
validators=[
DataRequired(),
Length(min=6),
EqualTo('password2',message="Passwords must match")
])
password2 = PasswordField(
'Confirm Password',
validators=[DataRequired()]
)
[MOD: added ```python formatting -cf]
2 Answers
David Smith
10,577 Pointsbump,
I have the same problem, the only validator that seems to work is the DataRequired.
Brian Peterson
Python Web Development Techdegree Student 13,634 PointsYou may have mistyped the variable name in the for loop of the macro.html file. See the following thread (this is what I was doing wrong to fix this bug): https://teamtreehouse.com/community/validation-form-not-working
Benjamin Stanger
Python Web Development Techdegree Student 7,974 PointsBenjamin Stanger
Python Web Development Techdegree Student 7,974 PointsI am also having this problem. I posted a question in the video questions area. Did you ever figure out your issue?