Bird
0
0

What is the issue with this APIView method?

medium📝 Debug Q6 of 15
Django - REST Framework Basics
What is the issue with this APIView method?
class SampleView(APIView):
    def get(self, request):
        return Response('Hello World')
AAPIView does not support the get method
BThe method should be named 'post' instead of 'get'
CResponse should return a dictionary or list, not a plain string
DResponse must include a status code explicitly
Step-by-Step Solution
Solution:
  1. Step 1: Understand Response data types

    DRF's Response expects data types like dict or list to serialize to JSON.
  2. Step 2: Analyze the code

    Returning a plain string without wrapping it in a dict or list can cause serialization issues.
  3. Final Answer:

    Response should return a dictionary or list, not a plain string -> Option C
  4. Quick Check:

    Response data must be serializable [OK]
Quick Trick: Always return dict or list in Response, not raw strings [OK]
Common Mistakes:
MISTAKES
  • Returning raw strings instead of JSON-serializable objects
  • Confusing HTTP method names
  • Assuming status code is mandatory in Response

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes