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 trialRobbin Khant Min
17,904 PointsI 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
cleaned_data= super().clean()
Can't I just use cleaned_data['something'] directly without calling cleaned_data=super( )?
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsIn 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.
In this 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!!