Complete the code to import the TokenAuthentication class from DRF.
from rest_framework.authentication import [1]
The TokenAuthentication class is imported from rest_framework.authentication to enable token-based authentication in DRF.
Complete the code to add TokenAuthentication to the default authentication classes in DRF settings.
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.[1]',
]
}Setting 'rest_framework.authentication.TokenAuthentication' in DEFAULT_AUTHENTICATION_CLASSES enables token auth globally.
Fix the error in the code to import the JWTAuthentication class from the djangorestframework_simplejwt package.
from rest_framework_simplejwt.authentication import [1]
The correct class to import for JWT auth from djangorestframework_simplejwt is JWTAuthentication.
Fill both blanks to configure JWTAuthentication and TokenAuthentication in DRF settings.
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.[1]',
'rest_framework.authentication.[2]',
]
}This config enables both JWT and Token authentication classes in DRF.
Fill all three blanks to create a view that uses JWTAuthentication and requires the user to be authenticated.
from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.permissions import [1] from rest_framework_simplejwt.authentication import [2] class MyView(APIView): authentication_classes = [[3]] permission_classes = [IsAuthenticated] def get(self, request): return Response({'message': 'Hello, authenticated user!'})
The permission class IsAuthenticated ensures only logged-in users access the view.
The authentication class JWTAuthentication is imported and used as a class reference in the list.