Created
March 12, 2014 07:55
-
-
Save nuty/9502630 to your computer and use it in GitHub Desktop.
jsonify for django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- 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