Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
django-method-override
Advanced tools
Django middleware that overrides the HTTP method through either a _method
form param (Ruby on Rails style) or the X-HTTP-Method-Override header.
Install via pip:
pip install django-method-override
Add the MethodOverrideMiddleware
after Django's CsrfViewMiddleware
:
MIDDLEWARE = (
# ...
'django.middleware.csrf.CsrfViewMiddleware',
'method_override.middleware.MethodOverrideMiddleware',
# ...
)
Add method_override
to your INSTALLED_APPS
:
INSTALLED_APPS = (
# ...
'method_override',
)
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/"
// ...
});
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 (c) 2013 LocalMed, Inc.. See LICENSE for details.
FAQs
Django Middleware for HTTP Method Override Form Params & Header
We found that django-method-override demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.