Bird
0
0

Given this DRF view snippet, what will be the response status code if an anonymous user tries to POST?

medium📝 Predict Output Q4 of 15
Django - DRF Advanced Features
Given this DRF view snippet, what will be the response status code if an anonymous user tries to POST?
from rest_framework.permissions import IsAuthenticated
class MyView(APIView):
permission_classes = [IsAuthenticated]
def post(self, request):
return Response({'message': 'Success'})
A200 OK
B403 Forbidden
C401 Unauthorized
D404 Not Found
Step-by-Step Solution
Solution:
  1. Step 1: Understand IsAuthenticated permission effect

    IsAuthenticated denies access to anonymous users, requiring authentication.
  2. Step 2: Identify HTTP status code for unauthenticated access

    DRF returns 401 Unauthorized when authentication is missing or invalid.
  3. Final Answer:

    401 Unauthorized -> Option C
  4. Quick Check:

    Anonymous POST with IsAuthenticated = 401 Unauthorized [OK]
Quick Trick: IsAuthenticated denies anonymous with 401 Unauthorized [OK]
Common Mistakes:
MISTAKES
  • Confusing 403 Forbidden with 401 Unauthorized
  • Assuming 200 OK for anonymous
  • Choosing 404 Not Found incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes