0
0
Djangoframework~10 mins

Handling different HTTP methods 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 check if the request method is GET.

Django
if request.method == '[1]':
    return HttpResponse('This is a GET request')
Drag options to blanks, or click blank then click option'
APOST
BDELETE
CPUT
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'get' instead of uppercase 'GET'.
Checking for 'POST' instead of 'GET'.
2fill in blank
medium

Complete the code to handle POST requests in a Django view.

Django
if request.method == '[1]':
    data = request.POST
    return HttpResponse('Received POST data')
Drag options to blanks, or click blank then click option'
APOST
BGET
CPUT
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' to check the method.
Trying to access request.GET for POST data.
3fill in blank
hard

Fix the error in the code to correctly handle PUT requests.

Django
if request.method == '[1]':
    # process PUT data
    return HttpResponse('Handled PUT request')
Drag options to blanks, or click blank then click option'
APUT
BGET
CPOST
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' or 'Post' instead of uppercase 'PUT'.
Checking for 'GET' or 'POST' instead of 'PUT'.
4fill in blank
hard

Fill both blanks to handle GET and POST methods in a Django view.

Django
if request.method == '[1]':
    return HttpResponse('GET request')
elif request.method == '[2]':
    return HttpResponse('POST request')
Drag options to blanks, or click blank then click option'
AGET
BPOST
CPUT
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the method names in the conditions.
Using lowercase method names.
5fill in blank
hard

Fill all three blanks to handle GET, POST, and DELETE methods in a Django view.

Django
if request.method == '[1]':
    return HttpResponse('GET request')
elif request.method == '[2]':
    return HttpResponse('POST request')
elif request.method == '[3]':
    return HttpResponse('DELETE request')
Drag options to blanks, or click blank then click option'
AGET
BPOST
CDELETE
DPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names or lowercase strings.
Mixing up the order of conditions.