Bird
0
0

Which of the following is the correct way to add TokenAuthentication to a Django REST Framework view?

easy📝 Syntax Q12 of 15
Django - DRF Advanced Features
Which of the following is the correct way to add TokenAuthentication to a Django REST Framework view?
Aauthentication_classes = ["rest_framework.authentication.TokenAuthentication"]
Bauthentication_classes = [TokenAuthentication]
Cauthentication_classes = [rest_framework.authentication.TokenAuthentication]
Dauthentication_classes = [TokenAuthentication()]
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to import and use authentication classes

    Authentication classes must be imported and instantiated, so use TokenAuthentication() not just the class name or string.
  2. Step 2: Check syntax for authentication_classes

    It expects a list of authentication class instances, so the correct syntax is [TokenAuthentication()] with parentheses.
  3. Final Answer:

    authentication_classes = [TokenAuthentication()] -> Option D
  4. Quick Check:

    Use class instances in list = A [OK]
Quick Trick: Use class instances with parentheses in authentication_classes list [OK]
Common Mistakes:
MISTAKES
  • Using strings instead of class instances
  • Forgetting parentheses after class name
  • Not importing TokenAuthentication before use

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes