Skip to content

Instantly share code, notes, and snippets.

@philippeowagner
Last active December 25, 2019 08:58
Show Gist options
  • Save philippeowagner/3179eb475fe1795d6515 to your computer and use it in GitHub Desktop.
Save philippeowagner/3179eb475fe1795d6515 to your computer and use it in GitHub Desktop.
JsonResponse for Django<=1.6, included in Django >= 1.7 https://docs.djangoproject.com/en/dev/ref/request-response/#jsonresponse-objects
from django.utils import simplejson
from django.http import HttpResponse
class JsonResponse(HttpResponse):
"""
JSON response
"""
def __init__(self, content, mimetype='application/json', status=None, content_type=None):
super(JsonResponse, self).__init__(
content=simplejson.dumps(content),
mimetype=mimetype,
status=status,
content_type=content_type,
)
@bellydrum
Copy link

Thank you so much for this. Unfortunately I can't upgrade my company's Django version so this will have to do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment