Bird
0
0

Consider the following Django REST Framework APIView:

medium📝 component behavior Q4 of 15
Django - REST Framework Basics
Consider the following Django REST Framework APIView:
from rest_framework.views import APIView
from rest_framework.response import Response

class GreetView(APIView):
    def get(self, request):
        return Response({"greeting": "Welcome to the API!"})

What will the browser display when you navigate to this view's URL?
AA plain HTML page with only the text 'Welcome to the API!'
BA browsable API page showing the JSON response with a form for GET requests
CA raw JSON string without any HTML formatting
DA 404 Not Found error because no template is specified
Step-by-Step Solution
Solution:
  1. Step 1: Identify the view type

    The view is a subclass of APIView returning a Response object with JSON data.
  2. Step 2: Understand DRF's default renderer behavior

    By default, DRF includes BrowsableAPIRenderer which renders a browsable HTML interface in browsers.
  3. Step 3: Result in browser

    When accessed via a browser, the response is rendered as an HTML page showing the JSON data and a form for GET requests.
  4. Final Answer:

    A browsable API page showing the JSON response with a form for GET requests -> Option B
  5. Quick Check:

    Browsable API renders HTML with JSON and forms [OK]
Quick Trick: Browsable API shows JSON plus forms in browsers [OK]
Common Mistakes:
MISTAKES
  • Assuming raw JSON is shown by default in browsers
  • Expecting plain HTML without JSON data
  • Thinking a template is required for APIView responses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes