0
0
Djangoframework~10 mins

Why Django built-in auth matters - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import Django's built-in authentication system.

Django
from django.contrib import [1]
Drag options to blanks, or click blank then click option'
Asessions
Bmessages
Cadmin
Dauth
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'sessions' instead of 'auth'.
Using 'admin' which is for site administration, not authentication.
2fill in blank
medium

Complete the code to check if a user is authenticated in a Django view.

Django
if request.user.[1]:
Drag options to blanks, or click blank then click option'
Ais_staff
Bis_authenticated
Chas_perm
Dis_active
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'is_active' which checks if the user account is active, not if logged in.
Using 'has_perm' which checks permissions, not authentication.
3fill in blank
hard

Fix the error in the code to log in a user using Django's auth system.

Django
from django.contrib.auth import [1]

user = authenticate(request, username='john', password='pass')
if user is not None:
    [1](request, user)
Drag options to blanks, or click blank then click option'
Aauthenticate
Blogout
Clogin
Dget_user
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'logout' instead of 'login'.
Calling 'authenticate' again instead of 'login'.
4fill in blank
hard

Fill both blanks to create a user with Django's built-in User model.

Django
from django.contrib.auth.models import [1]

user = [2].objects.create_user(username='alice', password='secret')
Drag options to blanks, or click blank then click option'
AUser
BGroup
CPermission
DAnonymousUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Group' or 'Permission' which are for roles and rights, not users.
Using 'AnonymousUser' which represents a non-logged-in user.
5fill in blank
hard

Fill all three blanks to check user permissions and log out in Django.

Django
from django.contrib.auth import [1]

if request.user.has_perm('[2]'):
    [3](request)
Drag options to blanks, or click blank then click option'
Alogout
Bauth.change_user
Cauth.delete_post
Dlogin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'login' instead of 'logout' to log out.
Using invalid permission strings.