Django Middleware for HTTP Method Override Form Params & Header
Project description
Django Method Override
Django middleware that overrides the HTTP method through either a _method
form param (Ruby on Rails style) or the X-HTTP-Method-Override header.
Installation
-
Install via pip:
pip install django-method-override
-
Add the
MethodOverrideMiddleware
after Django'sCsrfViewMiddleware
:MIDDLEWARE = ( # ... 'django.middleware.csrf.CsrfViewMiddleware', 'method_override.middleware.MethodOverrideMiddleware', # ... )
-
Add
method_override
to yourINSTALLED_APPS
:INSTALLED_APPS = ( # ... 'method_override', )
Usage
Use the provided template tag in your form to add the desired form:
{% load method_override %}
<form action="{% url 'post-detail' %}" method="POST">
{% csrf_token %}
{% method_override 'PUT' %}
</form>
Now, you may use put
in you Class-based views. Django Method Override will even copy over the form data to request.PUT
:
class PostView(View):
def put(self, request):
form = Form(request.PUT)
# ...
The X-HTTP-Method-Override header is also supported. So for the above view, this will work too:
$.ajax({
headers: { "X-HTTP-Method-Override": "PUT" },
type: "POST",
url: "http://localhost:8000/posts/1/"
// ...
});
Configuration
Django Method Override can be customized from your Django settings.py
file:
METHOD_OVERRIDE_ALLOWED_HTTP_METHODS
A list of the allowed methods for overriding. Defaults to:
['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'PATCH']
METHOD_OVERRIDE_PARAM_KEY
The form param key used to override the method. Defaults to '_method'
.
METHOD_OVERRIDE_HTTP_HEADER
The HTTP header to check. Defaults to 'HTTP_X_HTTP_METHOD_OVERRIDE'
METHOD_OVERRIDE_INPUT_TEMPLATE
The string tempalte used to render the input for the form param. It will based to kwargs, name
and value
. Defaults to:
'<input type="hidden" name="{name}" value="{value}">'
Copyright
Copyright (c) 2013 LocalMed, Inc.. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-method-override-1.0.4.tar.gz
.
File metadata
- Download URL: django-method-override-1.0.4.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8c9b6d4f5c565b63703f6619d89a2c5e6d5b1b2e7304372c275d779c8934fea |
|
MD5 | 9f80c82f1db842095d1acd05036566b5 |
|
BLAKE2b-256 | bc63ff0cb908aefce5b0dcf122c435d4a9bd55fe15745e7faf663e7a407395ae |
File details
Details for the file django_method_override-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: django_method_override-1.0.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0df5f7b84b8c41a8c6dc2e487a9e5782aa969dff0991fa8d9ba61f437fbf66f4 |
|
MD5 | 060224b781c7c6cca7dff87a7b74f923 |
|
BLAKE2b-256 | 0cdcfe63aa3cd22217c00b004953cb8049d1d0879611b7fac3638b0229b981c4 |