Bird
0
0

Given this APIView code, what will be the JSON response content when a GET request is made?

medium📝 component behavior Q4 of 15
Django - REST Framework Basics
Given this APIView code, what will be the JSON response content when a GET request is made?
class HelloView(APIView):
    def get(self, request):
        return Response({"message": "Hello, world!"})
A{"message": "Hello, world!"}
B{"error": "Not found"}
C"Hello, world!"
DAn empty JSON object {}
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the get() method

    The get() method returns a Response with a dictionary containing the key "message" and value "Hello, world!".
  2. Step 2: Understand Response serialization

    Response converts the dictionary to JSON, so the output is a JSON object with the message key.
  3. Final Answer:

    {"message": "Hello, world!"} -> Option A
  4. Quick Check:

    GET returns JSON with message key [OK]
Quick Trick: Response wraps dict to JSON automatically [OK]
Common Mistakes:
MISTAKES
  • Expecting plain string instead of JSON
  • Confusing error responses
  • Assuming empty response

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes