Last active
February 15, 2016 14:02
-
-
Save hannal/33dc38d232c5ee6d0514 to your computer and use it in GitHub Desktop.
django에 put, patch, delete method 추가.
This file contains 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
from django.http import QueryDict | |
from django.http.multipartparser import MultiValueDict | |
class MoreMethodsMiddleware(object): | |
def process_request(self, request): | |
method = request.META.get('REQUEST_METHOD', '').upper() | |
request.PUT = QueryDict('') | |
request.DELETE = QueryDict('') | |
request.PATCH = QueryDict('') | |
if method not in ('PUT', 'PATCH', 'DELETE', ): | |
return | |
data, request._file = self._parse_request(request) | |
setattr(request, method, data) | |
def _parse_request(self, request): | |
if request.META.get('CONTENT_TYPE', '').startswith('multipart'): | |
return request.parse_file_upload(request.META, request) | |
return QueryDict(request.body), MultiValueDict() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment