Friday 8 June 2012

Django and JSON - Easily Create a JSON Response

A simple guide on how to create a JSON response from Django.

Special thanks to these guys - http://stackoverflow.com/questions/2428092/django-python-creating-a-json-response.

---

some_key = '0'
response_data = dict()
nested_response_data = dict()

nested_response_data['result'] = 'failed'
nested_response_data['message'] = 'You messed up'
response_data[some_key] = nested_response_data

return HttpResponse(json.dumps(response_data), mimetype="application/json")

No comments:

Post a Comment