Created
November 21, 2013 21:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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