Django and JSON

/ Published in: Django
Save to your folder(s)

This function takes anything which can be dumped into JSON and returns an HTTP response of it, with the right Content-type header.

Copy this code and paste it in your HTML
  1. def json_response(something):
  2. from django.utils import simplejson
  3. return HttpResponse(simplejson.dumps(something),
  4. content_type='application/json; charset=UTF-8')

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.