0
0
Djangoframework~10 mins

Form fields and widgets in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Django form class.

Django
from django import [1]
Drag options to blanks, or click blank then click option'
Amodels
Bforms
Cviews
Dtemplates
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from django.models instead of django.forms
Using django.views or django.templates which are unrelated here
2fill in blank
medium

Complete 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'
AIntegerField
BDateField
CCharField
DEmailField
Attempts:
3 left
💡 Hint
Common Mistakes
Using IntegerField for text input
Using EmailField when a general text field is needed
3fill in blank
hard

Fix 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'
ATextarea
BTextInput
CCheckboxInput
DSelect
Attempts:
3 left
💡 Hint
Common Mistakes
Using TextInput instead of Textarea for multi-line input
Using CheckboxInput or Select which are unrelated widgets
4fill in blank
hard

Fill 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'
A{'placeholder': 'Enter your email'}
B{'class': 'email-input'}
C{'placeholder': 'Your email here'}
D{'id': 'email-field'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using class or id attributes instead of placeholder
Not using a dictionary for attrs
5fill in blank
hard

Fill 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'
AChoiceField
BGENDER_CHOICES
CRadioSelect
DCharField
Attempts:
3 left
💡 Hint
Common Mistakes
Using CharField instead of ChoiceField
Not passing the choices list
Using TextInput widget instead of RadioSelect