Skip to content

Instantly share code, notes, and snippets.

@ubombi
ubombi / middleware.py
Last active October 30, 2015 11:28 — forked from LucasRoesler/middleware.py
A Django middleware that process JSON data into the appropriate GET or POST variable. I use this with AngularJS, by default POST requests are sent as JSON instead of the urlencoded data expected by Django.
import json
from django.http import QueryDict
class JSONMiddleware(object):
"""
Process application/json requests data from GET and POST requests.
"""
def process_request(self, request):
if 'application/json' in request.META.get('CONTENT_TYPE', []):