Bird
0
0

How can you restrict the browsable API interface to only authenticated users while allowing JSON responses for all?

hard📝 Application Q9 of 15
Django - REST Framework Basics
How can you restrict the browsable API interface to only authenticated users while allowing JSON responses for all?
AUse a custom renderer class that checks user authentication before rendering browsable API
BRemove BrowsableAPIRenderer from DEFAULT_RENDERER_CLASSES
CSet permission_classes to IsAuthenticated globally
DDisable the browsable API in settings
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement

    We want browsable API only for authenticated users but JSON for all. This requires conditional rendering.
  2. Step 2: Evaluate options

    Removing browsable API or disabling it removes it for all. Setting IsAuthenticated blocks all API access. Custom renderer can check user and render accordingly.
  3. Final Answer:

    Use a custom renderer class that checks user authentication before rendering browsable API -> Option A
  4. Quick Check:

    Conditional renderer controls browsable API access [OK]
Quick Trick: Custom renderer can restrict browsable API by user [OK]
Common Mistakes:
MISTAKES
  • Blocking API access by setting global permissions
  • Removing browsable API for everyone

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes