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 trialRastko Jovic
14,883 PointsFLASK: Does the variable "form" automatically get set as attributes the data from the submitted form?
@app.route('/register', methods=('GET', 'POST')) def register(): form = forms.RegisterForm()
if form.validate_on_submit(): # <--- HERE
models.User.create_user(
username=form.username.data,
email=form.email.data,
password=form.password.data
)
return redirect(url_for('index'))
return render_template('register.html', form=form)
I don't understand how we can validate an empty form object when we haven't set the attribute values.Are they set automatically when the form is submitted ?
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsI think that's why the previous lines include
form = forms.RegisterForm()
Nick Osborne
4,612 PointsNick Osborne
4,612 PointsHi Yes, I believe the validate method returns true if the form validates correctly on submission.