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

Python Build a Social Network with Flask Takin' Names Form with Validators

Build a social Network with flask

Import Form from Flask-WTF. Import StringField and PasswordField from wtforms. Lastly, import DataRequired, Email, and Length from wtforms.validators

keeek getting a bummer

forms.py
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()]
    )

5 Answers

Hey Tafadzwa Timothy Gakaka

All that is required for this part of the challenge is the first part of your code:

from flask_wtf import Form
from wtforms import StringField, PasswordField
from wtforms.validators import (DataRequired, Regexp, ValidationError, Email,
                                Length, EqualTo)

what about part 3 and 4

What exactly are you stuck on? Feel free to share your code and the question and I will be happy to help! :)

from flask_wtf import Form from wtforms import StringField, PasswordField from wtforms.validators import (DataRequired, Regexp, ValidationError, Email, Length, EqualTo)

class SignUpForm(Form): email = StringField(validators=[DataRequired(), Email()])

password = PasswordField( 'password', validators=[ DataRequired(), Length(min=8) ])

im getting a bummer on You didn't create the password field(s). in the last part ,,,Finally, add DataRequired and Length to the validators for password. Set the min for Length to 8.

It looks like this code that you have works all the way through the 4 parts of the challenge. So it sounds like the challenge cached something incorrectly. Try restarting the entire challenge with the restart challenge button, and paste in your code and click check work all the way through the 4 parts.

Well done :D