Bird
0
0

Why does Django's JsonResponse require the safe parameter to be set to False when returning a list instead of a dictionary?

hard📝 Conceptual Q10 of 15
Django - REST Framework Basics
Why does Django's JsonResponse require the safe parameter to be set to False when returning a list instead of a dictionary?
ABecause by default JsonResponse only accepts dictionaries for security reasons
BBecause lists cannot be serialized to JSON
CBecause safe=False disables CSRF protection
DBecause safe=True converts lists to strings automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand JsonResponse safe parameter

    By default, JsonResponse expects a dictionary to prevent unsafe data exposure.
  2. Step 2: Explain why safe=False is needed for lists

    Setting safe=False allows sending non-dict JSON like lists, overriding the safety check.
  3. Final Answer:

    JsonResponse only accepts dictionaries by default for safety -> Option A
  4. Quick Check:

    safe=False allows non-dict JSON in JsonResponse [OK]
Quick Trick: safe=False lets JsonResponse send lists, not just dicts [OK]
Common Mistakes:
MISTAKES
  • Thinking lists cannot be JSON serialized
  • Confusing safe with CSRF protection
  • Assuming safe=True converts lists automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes