Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

bellydrum commented Mar 6, 2019

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