Skip to content

Instantly share code, notes, and snippets.

@hannal
Last active February 15, 2016 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannal/33dc38d232c5ee6d0514 to your computer and use it in GitHub Desktop.
Save hannal/33dc38d232c5ee6d0514 to your computer and use it in GitHub Desktop.
django에 put, patch, delete method 추가.
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