0
0
Djangoframework~10 mins

View decorators (require_GET, require_POST) 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 decorator that allows only GET requests.

Django
from django.views.decorators.http import [1]
Drag options to blanks, or click blank then click option'
Alogin_required
Brequire_POST
Crequire_GET
Dcsrf_exempt
Attempts:
3 left
💡 Hint
Common Mistakes
Using require_POST instead of require_GET
Importing unrelated decorators
2fill in blank
medium

Complete the code to decorate the view so it only accepts POST requests.

Django
@[1]
def submit_form(request):
    return HttpResponse('Form submitted')
Drag options to blanks, or click blank then click option'
Arequire_POST
Brequire_GET
Ccsrf_exempt
Dlogin_required
Attempts:
3 left
💡 Hint
Common Mistakes
Using require_GET instead of require_POST
Forgetting to add the decorator
3fill in blank
hard

Fix the error in the code by completing the decorator import correctly.

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

@require_GET
def show_data(request):
    return HttpResponse('Data shown')
Drag options to blanks, or click blank then click option'
ArequirePost
Brequire_post
CrequireGet
Drequire_GET
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or camelCase names
Misspelling the decorator name
4fill in blank
hard

Fill both blanks to create a view that only accepts GET requests and returns a simple response.

Django
from django.http import HttpResponse
from django.views.decorators.http import [1]

@[2]
def home(request):
    return HttpResponse('Welcome!')
Drag options to blanks, or click blank then click option'
Arequire_GET
Brequire_POST
Ccsrf_exempt
Dlogin_required
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing require_POST with require_GET
Forgetting to import the decorator
5fill in blank
hard

Fill all three blanks to create a POST-only view that returns a confirmation message.

Django
from django.http import HttpResponse
from django.views.decorators.http import [1]

@[2]
def submit(request):
    if request.method == '[3]':
        return HttpResponse('Submitted successfully')
Drag options to blanks, or click blank then click option'
Arequire_GET
Brequire_POST
CPOST
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using require_GET decorator with POST method
Checking for wrong HTTP method string