Skip to content

Instantly share code, notes, and snippets.

@gonz
Created November 21, 2013 21:30
Show Gist options
  • Save gonz/7590028 to your computer and use it in GitHub Desktop.
Save gonz/7590028 to your computer and use it in GitHub Desktop.
In django PUT and DELETE request doesn't get from params parsed in django, IMO they should be handled exaclty like a POST request and end up in request.POST (yes I know it's a bad name...). request.GET stores query/url params and request.POST form/body params.
"""
In django PUT and DELETE request doesn't get from params parsed in django, IMO
they should be handled exaclty like a POST request and end up in request.POST
(yes I know it's a bad name...).
request.GET stores query/url params and request.POST form/body params.
"""
from django.http import QueryDict
class FormParamsMiddleware(object):
def process_request(self, request):
method = request.META.get('REQUEST_METHOD', '').upper()
if method not in ['PUT', 'DELETE']:
return None
content_type = request.META.get('CONTENT_TYPE', '')
if content_type.startswith('multipart'):
request.POST, request.FILES = request.parse_multipart(request.META,
request)
elif content_type.startswith('application/x-www-form-urlencoded'):
request.POST = QueryDict(request.body, encoding=request._encoding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment