Skip to main content

Provide a workaround to use different method from GET or POST inside HTML forms

Project description

Python package codecov CodeFactor PyPI Version Python 3.5+ Django 2+, 3+ License MIT

django-http-method

Provide a workaround to use different method than GET or POST inside HTML forms in django templates. Works only with Class Based View.

Installation

From source code:

python setup.py install

From pip:

pip install django-http-method

Usage

Add django_http_method to your settings.INSTALLED_APPS
INSTALLED_APPS = (
    [...],
    django_http_method,
    [...],
)
Add the mixin to a CBV
from django.views.generic import View
from django_http_method import HttpMethodMixin

class TestView(HttpMethodMixin, View):
	
	def get(self, request):
		pass
	
	def delete(self, request):
		pass
	
	def put(self, request):
		pass
	
	[...]
In your template, load http_method and use {% http_[method] %} in your forms:
{% load http_method %}

<form action="/" method="post">
    {% csrf_token %}
    {% http_put %}
    [...]
    <button type="submit">Send a PUT request</button>
</form>


<form action="/" method="post">
    {% csrf_token %}
    {% http_patch %}
    [...]
    <button type="submit">Send a PATCH request</button>
</form>

The corresponding method of your View will now be called. For instance, if {% http_put %} was used, then TestView.put() will be called and any request parameter will be in request.PUT.


Changelog

1.2.1

  • Renamed template directory to django_http_method.

1.2.0

  • Dropped Django 1.X support.
  • Now supports Django 3.2.

1.1.1

  • Now use Github action for testing and deployment

1.1.0

  • Dropped python 3.4 support
  • Now support django 3.0

1.0.2

  • Added pyaml to setup requirement.

1.0.1

  • Now use yaml.safe_load() instead of yaml.load()
  • Added python 3.7 and django 2.1 to test matrix

1.0.0

  • Initial release for python3.4+ and django1.8, 1.10, 1.11 and 2.0+

0.4.0

  • Will now search for parameters in body for methods PUT and PATCH
  • Method will default to request.method if '_method' parameter was not found

0.3.2

  • Added end slash '/' at the end of HTML input in templatetags

0.3.0

  • Removing '_method' from request parameters

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

django-http-method-1.2.1.tar.gz (7.4 kB view details)

Uploaded Source

File details

Details for the file django-http-method-1.2.1.tar.gz.

File metadata

  • Download URL: django-http-method-1.2.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for django-http-method-1.2.1.tar.gz
Algorithm Hash digest
SHA256 ebbe23f7cae08a33dde516f9e0861b83c5966bf6598b0c12c79b1fc7a6fcae49
MD5 c1248e996f3e5121b44fa1f8751c591e
BLAKE2b-256 c2732c80a2a121eb0d2762ae8de663dbb004e37ab64712bdda4d8ea9eb207076

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page