Skip to main content

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

  1. django-htmx-refresh relies on the django-htmx package. You can install it with pip:

pip install django-htmx
  1. Add “django_htmx_refresh” to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...
    'django_htmx_refresh',
]
  1. 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.

  1. 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.

  1. 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.

  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-htmx-refresh-0.0.7.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_htmx_refresh-0.0.7-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file django-htmx-refresh-0.0.7.tar.gz.

File metadata

  • Download URL: django-htmx-refresh-0.0.7.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for django-htmx-refresh-0.0.7.tar.gz
Algorithm Hash digest
SHA256 69ee141fe12f524a3d53b6039105881099435c72ded31dd5ffa1850a0e4ea25f
MD5 f9a46dffbb25e1051f4e82c3019c4673
BLAKE2b-256 62efd52c7370474d383b7d3f4087a975c46f0f1781ad8bd8327793095bf8dff2

See more details on using hashes here.

File details

Details for the file django_htmx_refresh-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_htmx_refresh-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 638e6739a4fea0dcae45bed7f70774097af00a4411dda29a32855278e9d0dba9
MD5 c10b4771383b5a7970aaa85816aebebd
BLAKE2b-256 ab41ec715b0d80a7954ef48f11647871c65d7521cdf80b49aa319e6aced0bfd1

See more details on using hashes here.

Supported by

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