Skip to content

Instantly share code, notes, and snippets.

@theeluwin
Created July 9, 2013 07:00
Show Gist options
  • Select an option

  • Save theeluwin/5955244 to your computer and use it in GitHub Desktop.

Select an option

Save theeluwin/5955244 to your computer and use it in GitHub Desktop.
Making PUT and DELETE method reasonable for restful django.
def refine(request):
method = request.method
if method == 'PUT' or method == 'DELETE':
if hasattr(request, '_post'):
del request._post
del request._files
try:
request.method = 'POST'
request._load_post_and_files()
request.method = method
except AttributeError:
request.META['REQUEST_METHOD'] = 'POST'
request._load_post_and_files()
request.META['REQUEST_METHOD'] = method
request.PUT = request.POST
request.DELETE = request.POST
return request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment