Skip to content

Instantly share code, notes, and snippets.

@nuty
Created March 12, 2014 07:55
Show Gist options
  • Save nuty/9502630 to your computer and use it in GitHub Desktop.
Save nuty/9502630 to your computer and use it in GitHub Desktop.
jsonify for django
#-*- coding:utf8 -*-
from django.utils import simplejson as json
from django.http import HttpResponse
def jsonify(*args, **kwargs):
if len(args) == 1:
content = json.dumps(args[0])
else:
content = json.dumps(dict(*args, **kwargs))
response = HttpResponse(content=content, mimetype="application/json")
response['Cache-Control'] = 'no-cache'
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment