Bird
0
0

You want to customize the browsable API interface to add a new header and change the form layout for a POST endpoint. Which approach is correct?

hard📝 Application Q15 of 15
Django - REST Framework Basics
You want to customize the browsable API interface to add a new header and change the form layout for a POST endpoint. Which approach is correct?
AOverride the <code>renderer_classes</code> in your view to use a custom renderer subclassing <code>BrowsableAPIRenderer</code>
BModify the Django <code>settings.py</code> to add new HTML templates for the browsable API
CChange the <code>urls.py</code> to point to a custom HTML page instead of the API view
DAdd JavaScript in the API response to modify the browsable API page
Step-by-Step Solution
Solution:
  1. Step 1: Understand how browsable API customization works

    The browsable API uses renderer classes to generate its HTML interface. Customizing it requires subclassing BrowsableAPIRenderer.
  2. Step 2: Apply customization in the view

    Override renderer_classes in your API view to use your custom renderer that adds headers or changes form layout.
  3. Final Answer:

    Override the renderer_classes in your view to use a custom renderer subclassing BrowsableAPIRenderer -> Option A
  4. Quick Check:

    Customize browsable API = custom renderer class [OK]
Quick Trick: Customize browsable API via renderer_classes override [OK]
Common Mistakes:
MISTAKES
  • Trying to change settings.py templates (not supported)
  • Replacing URLs with HTML pages (breaks API)
  • Injecting JavaScript in API response (ineffective)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes