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 Task 2 of 4

The second task asks "Create a new Form class named SignUpForm. Give it two fields, email and password. email should be a StringField and password should be a PasswordField."

I've tried creating objects without any parameters in the code block below, but have also tried passing in validators. In all cases I get a "Bummer! You didn't create the field(s)." error. It seems like I'm doing exactly what the task is asking for, and also what was done in the videos... am I missing something?

forms.py
from wtforms import Form, StringField, PasswordField
from wtforms.validators import DataRequired, Email, Length

class SignUpForm(Form):
    email = StringField()
    password = PasswordField()
Cheo R
Cheo R
37,150 Points

I hanv't taken this track yet, but looking at Flask's example code for Form, found here, it includes:

from wtforms import Form, BooleanField, StringField, PasswordField, validators

class RegistrationForm(Form):
    username = StringField('Username', [validators.Length(min=4, max=25)])
    email = StringField('Email Address', [validators.Length(min=6, max=35)])
    password = PasswordField('New Password', [
        validators.DataRequired(),
        validators.EqualTo('confirm', message='Passwords must match')
    ])
    confirm = PasswordField('Repeat Password')
    accept_tos = BooleanField('I accept the TOS', [validators.DataRequired()])

4 Answers

Ina Bankyn
Ina Bankyn
5,434 Points

I had the same problem. Then I figured out, that my imported modules are not the right ones.

Form needs to be imported from flask_wtf and not from wtforms.

from flask_wtf import Form
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired, Email, Length

class SignUpForm(Form):
    email = StringField(validators=[DataRequired(), Email()])
    password = PasswordField(validators=[DataRequired(), Length(min=8)])
Kenneth Giorno
Kenneth Giorno
4,043 Points

Having the same trouble as you John, I've tried the same four variants, and the code seems to work when run from terminal so I'm thinking there might be something up with the task validation.

This should work

class SignUpForm(Form): email = StringField('Email') password = PasswordField('Password')

Hrmmm... I've tried both :

class SignUpForm(Form): 
    email = StringField('Email')
    password = PasswordField('Password')

("Bummer! You didn't create the field(s).") and

class SignUpForm(Form):

    def __init__(self):
        self.email = StringField("Email")
        self.password = PasswordField("Password")

(Bummer! Try again!)

I've also tried Cheo's suggestion of using code from the Flask docs and still get the "Bummer! Try again!" error:

class SignUpForm(Form):

    def __init__(self):
        username = StringField('Username', [Length(min=4, max=25)])
        email = StringField('Email Address', [Length(min=6, max=35)])
        password = PasswordField('New Password', [DataRequired()])
class SignUpForm(Form):
    email = StringField(
        'Email')

    password = PasswordField(
        'Password')