Recall & Review
beginner
What does the
is_valid() method do in a Django form?The
is_valid() method checks if the form data meets all validation rules. It returns True if the data is valid, otherwise False. It also prepares cleaned data for use.Click to reveal answer
beginner
What is
cleaned_data in Django forms?cleaned_data is a dictionary that holds the validated and converted form data after is_valid() is called. It contains safe data you can use in your code.Click to reveal answer
beginner
When should you access
cleaned_data in a Django form?You should access
cleaned_data only after is_valid() returns True. Accessing it before validation may cause errors.Click to reveal answer
intermediate
How can you add custom validation logic in a Django form?
You can add a method named
clean_fieldname() for a specific field or override the clean() method for the whole form to add custom validation.Click to reveal answer
beginner
What happens if
is_valid() returns False?If
is_valid() returns False, the form has errors. You can check form.errors to see what went wrong and show messages to the user.Click to reveal answer
What does
form.is_valid() return if the form data is correct?✗ Incorrect
is_valid() returns True when all form data passes validation.Where do you find the cleaned and safe form data after validation?
✗ Incorrect
cleaned_data holds the validated and converted form data.When should you NOT access
form.cleaned_data?✗ Incorrect
Accessing
cleaned_data before validation can cause errors.How do you add validation for a single field in a Django form?
✗ Incorrect
Custom validation for a field uses
clean_fieldname().What attribute contains error messages if validation fails?
✗ Incorrect
form.errors holds error messages after failed validation.Explain how
is_valid() and cleaned_data work together in Django form validation.Think about the order of validation and data access.
You got /4 concepts.
Describe how to add custom validation to a specific field in a Django form.
Focus on naming and purpose of the method.
You got /4 concepts.