Posting JSON Data to a Django App

From Littledamien Wiki
Revision as of 16:36, 22 February 2013 by Video8 (talk | contribs) (→‎External resources)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview[edit]

The goal is to create a Django app that accepts JSON data via POST requests.

External resources[edit]

Testing POST data with curl[edit]

By default Django checks for Cross Site Request Forgery (CSRF) for POST requests. This will cause a 403 response for curl requests that don't include csrf token values in the POST data.

Maybe curl isn't the correct way to test POST requests. Maybe it should be done with Django tests instead.

One way around this is to mark a view as being exempt from CSRF protection:

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def my_view(request):
    return HttpResponse('Hello world')