A Django app to handle HTMX page reloads.
Project description
This is a Django app to handle full-page reloads with HTMX.
There are two possible use-cases for this app.
Quick start
django-htmx-refresh relies on the django-htmx package. You can install it with pip:
pip install django-htmx
Add “django_htmx_refresh” to your INSTALLED_APPS setting:
INSTALLED_APPS = [ ... 'django_htmx_refresh', ]
Include an app namespace for your project’s urls:
path('app_path', include(('app.urls', 'app_namespace'))),
Middleware
For when you want to handle htmx requests in all the views of a particular app.
Create a new list in your settings called HTMX_APPS:
HTMX_APPS = [ 'app_namespace' ]
This is so our custom middleware class only affects apps we explicity define, preventing errors with other third-party apps such as the default django admin application.
Add HtmxResponseMiddleware to the MIDDLEWARE setting:
MIDDLEWARE = [ ... 'django_htmx_refresh.middleware.HtmxResponseMiddleware', ]
Note: The HtmxReseponseMiddleware class provided with this application uses the process_template_response hook, meaning any view you intend to be used with this class must return a response object that implements a render method. Luckily Django’s class-based views do this for us with TemplateResponse.
Mixin
For when you want to handle htmx requests in most of your views but not necessarily all of them.
Import the HtmxResponseMixin and add it to your view(s).
from django_htmx_refresh.mixins import HtmxResponseMixin class ExampleView(TemplateView, HtmxResponseMixin): template_name = 'template_name.html'
Project details
Release history Release notifications | RSS feed
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
Hashes for django-htmx-refresh-0.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4c01292faa52635baf9aa9669a32ce7dfa50fb5c1e55882fcc9921c3e5837d1 |
|
MD5 | de06ca80b1a68448a5e649d33dc0661a |
|
BLAKE2b-256 | dd14a9dd99b6561cc3cae901187efdeed32a23f656d086a4b165e5ae0e687fb1 |
Hashes for django_htmx_refresh-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d70392ba5ef545001e2dd159cf8620ac1d642f555d7cb6f02448218d967b0c02 |
|
MD5 | ca1332b46dbdce96731ef3bf28d60842 |
|
BLAKE2b-256 | bae9cf9c7a8ba76bd28978f18a5bcc7c94892eeb17d54029d8685fac3ef791a1 |