0
0
Djangoframework~10 mins

View base class 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 base view class from Django.

Django
from django.views import [1]
Drag options to blanks, or click blank then click option'
AForm
BModel
CTemplate
DView
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Model' instead of 'View' for importing the base view class.
Confusing 'Template' or 'Form' with the base view class.
2fill in blank
medium

Complete the code to create a simple class-based view inheriting from the base view.

Django
class MyView([1]):
    pass
Drag options to blanks, or click blank then click option'
ATemplateView
BView
CFormView
DListView
Attempts:
3 left
💡 Hint
Common Mistakes
Using specialized views like 'TemplateView' or 'ListView' when the base class is needed.
Forgetting to inherit from any class.
3fill in blank
hard

Fix the error in the method name to handle GET requests in a class-based view.

Django
class MyView(View):
    def [1](self, request):
        return HttpResponse('Hello')
Drag options to blanks, or click blank then click option'
AGET
BGet
Cget
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or capitalized method names like 'Get' or 'GET'.
Using unrelated method names like 'fetch'.
4fill in blank
hard

Fill both blanks to correctly import HttpResponse and define a GET method returning a response.

Django
from django.http import [1]

class MyView(View):
    def get(self, request):
        return [2]('Hello World')
Drag options to blanks, or click blank then click option'
AHttpResponse
BHttpRequest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing HttpRequest instead of HttpResponse.
Returning HttpRequest instead of HttpResponse.
5fill in blank
hard

Fill all three blanks to create a class-based view that handles POST requests and returns a simple response.

Django
from django.views import [1]
from django.http import [2]

class SubmitView([3]):
    def post(self, request):
        return HttpResponse('Submitted')
Drag options to blanks, or click blank then click option'
AView
BHttpResponse
DTemplateView
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'TemplateView' instead of 'View' for the base class.
Not importing HttpResponse correctly.