Bird
0
0

Why does this DRF view raise an error?

medium📝 Debug Q7 of 15
Django - DRF Advanced Features
Why does this DRF view raise an error?
class MyView(APIView):
permission_classes = [IsAuthenticated()]
def get(self, request):
return Response({'msg': 'Hi'})
AResponse is not imported
BIsAuthenticated cannot be used with APIView
Cget method must return a string, not dict
Dpermission_classes should contain classes, not instances
Step-by-Step Solution
Solution:
  1. Step 1: Check permission_classes content

    permission_classes expects a list of classes, not instances (no parentheses).
  2. Step 2: Identify correct usage

    Use permission_classes = [IsAuthenticated] without parentheses to avoid errors.
  3. Final Answer:

    permission_classes should contain classes, not instances -> Option D
  4. Quick Check:

    Use classes, not instances in permission_classes [OK]
Quick Trick: No parentheses when listing permission classes [OK]
Common Mistakes:
MISTAKES
  • Using parentheses creating instances
  • Wrong method return types
  • Missing imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes