Complete the code to import Django's built-in authentication system.
from django.contrib import [1]
Django's built-in authentication system is accessed via django.contrib.auth. This module provides user management features.
Complete the code to check if a user is authenticated in a Django view.
if request.user.[1]:
Use is_authenticated to check if the user is logged in. It returns True for authenticated users.
Fix the error in the code to log in a user using Django's auth system.
from django.contrib.auth import [1] user = authenticate(request, username='john', password='pass') if user is not None: [1](request, user)
The login function logs in the user after authentication. The code imports and calls login.
Fill both blanks to create a user with Django's built-in User model.
from django.contrib.auth.models import [1] user = [2].objects.create_user(username='alice', password='secret')
The User model is imported and used to create a new user with create_user.
Fill all three blanks to check user permissions and log out in Django.
from django.contrib.auth import [1] if request.user.has_perm('[2]'): [3](request)
The logout function logs out the user. The permission string must be a valid permission like auth.change_user.