Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between JsonResponse and HttpResponse in django

Tags:

python

django

Lets say result = {'a': 1, 'b': 2, 'c': 3}

Is there a difference between these two:

return HttpResponse(json.dumps(a))

and

return JsonResponse(a)
like image 365
shreesh katti Avatar asked Feb 11 '19 10:02

shreesh katti


1 Answers

As doc states, main difference is

  • automatic serialization
  • proper content type
  • safer input check by default
like image 110
Slam Avatar answered Nov 08 '22 20:11

Slam