Skip to content

Instantly share code, notes, and snippets.

@flavianmissi
Created December 13, 2011 17:57
Show Gist options
  • Save flavianmissi/1473120 to your computer and use it in GitHub Desktop.
Save flavianmissi/1473120 to your computer and use it in GitHub Desktop.
Simple json response generic view
from django.views.generic import View
from django.utils import simplejson
class JSONResponseView(View):
def render_to_response(self, data, **httpresponse_kwargs):
"Retuns a json response based on the context"
json_data = simplejson.dumps(data)
return HttpResponse(json_data, content_type="application/json", **httpresponse_kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment