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!
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
I thought cleaned_data is a built in method
In previous videos , we just used
if form.is_valid(): send_mail( form.cleaned_data['suggestion'], )
no need to call
Can't I just use cleaned_data['something'] directly without calling cleaned_data=super( )?
Chris FreemanTreehouse Moderator 68,404 Points
In your top example,
form.cleaned_data is created by running the
form.is_valid() method. This method checks all of the fields and creates the attribute
cleaned_data as a dictionary of field names and values.
The docs say:
A Form instance has an is_valid() method, which runs validation routines for all its fields. When this method is called, if all fields contain valid data, it will:
- return True
- place the form’s data in its cleaned_data attribute.
clean method, the goal is to verify the data entered is correct beyond just meeting the field description requirements.
More information available in the docs "Cleaning and validating fields that depend on each other"
Post back if you need more help. Good luck!!