Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Django form class.
Django
from django import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from django.models instead of django.forms
Using django.views or django.templates which are unrelated here
✗ Incorrect
The forms module is used to create form classes in Django.
2fill in blank
mediumComplete the code to define a CharField with a max length of 100.
Django
name = forms.[1](max_length=100)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using IntegerField for text input
Using EmailField when a general text field is needed
✗ Incorrect
CharField is used for text input with a maximum length.
3fill in blank
hardFix the error in the widget assignment to use a Textarea widget.
Django
description = forms.CharField(widget=forms.[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using TextInput instead of Textarea for multi-line input
Using CheckboxInput or Select which are unrelated widgets
✗ Incorrect
The Textarea widget creates a multi-line text box for input.
4fill in blank
hardFill both blanks to create an EmailField with a placeholder attribute.
Django
email = forms.EmailField(widget=forms.TextInput(attrs=[1])) # attrs dictionary example: [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using class or id attributes instead of placeholder
Not using a dictionary for attrs
✗ Incorrect
The attrs dictionary sets HTML attributes like placeholder text.
5fill in blank
hardFill all three blanks to create a ChoiceField with radio buttons and choices.
Django
GENDER_CHOICES = [
('M', 'Male'),
('F', 'Female'),
('O', 'Other')
]
gender = forms.[1](
choices=[2],
widget=forms.[3]()
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using CharField instead of ChoiceField
Not passing the choices list
Using TextInput widget instead of RadioSelect
✗ Incorrect
ChoiceField is used for selecting one option from choices.
The choices argument takes a list of tuples.
The RadioSelect widget shows options as radio buttons.