Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the form data is valid.
Django
if form.[1](): print("Valid data")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cleaned_data() instead of is_valid()
Calling save() before validation
✗ Incorrect
The is_valid() method checks if the form data passes all validation rules.
2fill in blank
mediumComplete the code to access the cleaned form data after validation.
Django
if form.is_valid(): name = form.[1]['name']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access data before calling is_valid()
Using errors instead of cleaned_data
✗ Incorrect
The cleaned_data dictionary contains the validated and converted form data.
3fill in blank
hardFix the error in accessing cleaned data from the form.
Django
if form.is_valid(): age = form.cleaned_data[1]('age')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets
Trying to call cleaned_data as a function
✗ Incorrect
The cleaned_data is a dictionary, so use square brackets [] to access values by key.
4fill in blank
hardFill both blanks to validate the form and print the cleaned email.
Django
if form.[1](): print(form.cleaned_data[2]['email'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation instead of square brackets for cleaned_data
Forgetting parentheses on is_valid
✗ Incorrect
Use is_valid() to check validity and square brackets [] to access cleaned data.
5fill in blank
hardFill both blanks to validate the form, get the username, and print it.
Django
if form[1]: username = form.cleaned_data[2]['username'] print(username)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing parentheses on is_valid
Using parentheses instead of square brackets for cleaned_data
Adding extra parentheses in print
✗ Incorrect
Call is_valid() to validate, use square brackets [] to get username, and print the variable directly.