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 trialJohn Vlahos
4,697 PointsBuild 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?
from wtforms import Form, StringField, PasswordField
from wtforms.validators import DataRequired, Email, Length
class SignUpForm(Form):
email = StringField()
password = PasswordField()
4 Answers
Ina Bankyn
5,434 PointsI 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
4,043 PointsHaving 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.
Roan Shetty
160 PointsThis should work
class SignUpForm(Form): email = StringField('Email') password = PasswordField('Password')
John Vlahos
4,697 PointsHrmmm... 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()])
ASHOK Gudivada
11,701 Pointsclass SignUpForm(Form):
email = StringField(
'Email')
password = PasswordField(
'Password')
Cheo R
37,150 PointsCheo R
37,150 PointsI hanv't taken this track yet, but looking at Flask's example code for Form, found here, it includes: