0
0
Djangoframework~10 mins

Logout view 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 logout function from Django's auth module.

Django
from django.contrib.auth import [1]
Drag options to blanks, or click blank then click option'
Aauthenticate
Blogin
Clogout
Dget_user
Attempts:
3 left
💡 Hint
Common Mistakes
Importing login instead of logout
Importing authenticate which is for login
Forgetting to import logout
2fill in blank
medium

Complete the logout view function to call the logout method with the request.

Django
def logout_view(request):
    [1](request)
    # redirect after logout
Drag options to blanks, or click blank then click option'
Alogout
Blogin
Cauthenticate
Dget_user
Attempts:
3 left
💡 Hint
Common Mistakes
Calling login instead of logout
Forgetting to pass the request argument
Calling authenticate which is for login
3fill in blank
hard

Fix the error in the logout view by completing the redirect import statement.

Django
from django.shortcuts import [1]
Drag options to blanks, or click blank then click option'
Aredirect
BHttpResponse
Cget_object_or_404
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Importing render instead of redirect
Importing HttpResponse which is not for redirects
Forgetting to import redirect
4fill in blank
hard

Fill both blanks to complete the logout view that logs out and redirects to home.

Django
def logout_view(request):
    [1](request)
    return [2]('home')
Drag options to blanks, or click blank then click option'
Alogout
Bredirect
Crender
Dlogin
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of redirect
Calling login instead of logout
Not returning a redirect response
5fill in blank
hard

Fill all three blanks to create a complete logout view with import, logout call, and redirect.

Django
from django.contrib.auth import [1]
from django.shortcuts import [2]

def logout_view(request):
    [3](request)
    return redirect('login')
Drag options to blanks, or click blank then click option'
Alogout
Bredirect
Clogin
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Importing login instead of logout
Using render instead of redirect
Calling login instead of logout in the view