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 trial
Christopher Gomez
Courses Plus Student 13,800 PointsBummer! SyntaxError: Length, EqualTo
Challenge Task 1 of 4
Import Form from Flask-WTF. Import StringField and PasswordField from wtforms. Lastly, import DataRequired, Email, and Length from wtforms.validators.
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 email_exists(form, field):
if User.select.where(User.email == field.data).exists():
raise ValidationError('User with that email already exists.')
def name_exists(form, field):
if User.select.where(User.username == field.data).exists():
raise ValidationError('User with that name already exists.')
class RegisterForm(Form):
username = StringField(
'Username',
validators=[
DataRequired(),
Regexp(
r'^[a-zA-Z0-9_]+$',
message=("Username should be one word, letters, "
"numbers and underscores only.")
),
name_exists
])
email = StringField(
'Email',
validators=[
DataRequired(),
Email(),
email_exists
])
password = PasswordField(
'Password',
validators=[
DataRequired(),
Length(min=2),
EqualTo('password2', message='Password must match')
])
password2 = PasswordField(
'Confirm password',
validators=[ DataRequired()]
)
Having trouble figuring this out been looking at examples and still can't figure out the answer even copied straight from the video.
3 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Christopher
The only thing i can spot here, you missing a ',' between the imports Email and Length.
from wtforms.validators import (DataRequired, Regexp, ValidationError, Email # add a , here
Length, EqualTo)
Let me know if this fixes the issue
Christopher Gomez
Courses Plus Student 13,800 Points@Andreas cormack thanks for your help!
Tafadzwa Timothy Gakaka
10,978 PointsBummer: ModuleNotFoundError: No module named 'models'
after i put the comma