Created
May 24, 2012 17:35
-
-
Save kotobukid/2782966 to your computer and use it in GitHub Desktop.
from django return json(decorator)
This file contains 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:utf-8 | |
from django.http import HttpResponse | |
from django.utils import simplejson | |
def jsonize(original_func): | |
def decorated_func(*args, **kwargs): | |
if "callback" in args[0].GET: | |
ret = original_func(*args, **kwargs) | |
return HttpResponse('%s(%s)' % (args[0].GET["callback"], | |
simplejson.dumps(ret, | |
ensure_ascii=False)), | |
mimetype="text/javascript") | |
else: | |
ret = original_func(*args, **kwargs) | |
return HttpResponse(simplejson.dumps(ret, ensure_ascii=False), | |
mimetype="text/javascript") | |
return decorated_func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"ret" must be serializable