0
0
Djangoframework~10 mins

Form class definition 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 forms module.

Django
from django import [1]
Drag options to blanks, or click blank then click option'
Amodels
Bviews
Cadmin
Dforms
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'models' instead of 'forms'.
Forgetting to import the forms module.
2fill in blank
medium

Complete the code to define a form class named ContactForm inheriting from Django's base form class.

Django
class ContactForm([1]):
    pass
Drag options to blanks, or click blank then click option'
AHttpResponse
Bforms.Form
Cmodels.Model
Dviews.View
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from 'models.Model' instead of 'forms.Form'.
Using unrelated base classes like 'HttpResponse'.
3fill in blank
hard

Fix the error in the form field definition to create a CharField with a max length of 100.

Django
class ContactForm(forms.Form):
    name = forms.CharField([1]=100)
Drag options to blanks, or click blank then click option'
Amax_length
Bmaxsize
Clength
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'maxsize' or 'length' which are not valid arguments.
Omitting the max length argument.
4fill in blank
hard

Fill both blanks to define an EmailField with a required attribute set to True.

Django
class ContactForm(forms.Form):
    email = forms.[1](required=[2])
Drag options to blanks, or click blank then click option'
AEmailField
BTrue
CFalse
DCharField
Attempts:
3 left
💡 Hint
Common Mistakes
Using CharField instead of EmailField for emails.
Setting required to False when the field should be mandatory.
5fill in blank
hard

Fill all three blanks to define a form with a CharField named username, a PasswordInput widget, and a max length of 30.

Django
class UserForm(forms.Form):
    username = forms.[1](max_length=[2], widget=forms.[3]())
Drag options to blanks, or click blank then click option'
ACharField
B30
CPasswordInput
DEmailField
Attempts:
3 left
💡 Hint
Common Mistakes
Using EmailField instead of CharField for username.
Forgetting to set max_length or widget properly.