Skip to main content

Django HTMX Integration

Project description

Djxi | HTMX Integration for modern Django Frontends

CI pre-commit Lint codecov

PyPI PyPI - Wheel PyPI - Python Version


📦 What is this?

Stop hunting for HTMX endpoints.
Djxi bundles the route, the view logic, and the HTML partial into a single Endpoint Battery. Drop the DxActionRouter into your existing Django views or use it standalone. Keep every tiny hx-* swap exactly where it lives—without scattering your code across urls.py, views/, and templates/.

  • No more archaeology. No more digging through three files just to tweak a button label.
  • LoB, restored. Request → Logic → Render stays in one atomic, inline hub.
  • Scales cleanly. Small partials stay manageable, without turning your project into spaghetti.

Just a prenup between Grandpa Django and his sexy new HTMX fling—keeping your repo clean, one battery at a time.

Pre-Alpha Note

The package is considered in experimental pre-alpha state, use with caution.

  • Watch out for updates and consider giving it a star.
  • Checkout the djxi showcases in the example django app.

Getting Started

Instalation

  1. Install with pip:

python -m pip install djxi

  1. Add django-htmx to your INSTALLED_APPS:
INSTALLED_APPS = [
    ...,
    "djxi",
    ...,
]
  1. Optional: Adjust your base template to get you up and running instantly
 {% load djxi %}
 <!doctype html>
 <html>
   <head>
     ...
     {% htmx_script_inclusion %}
   </head>
   <body {% htmx_headers %}>
     ...
   </body>
 </html>

The htmx_script_inclusion tag will pull the unminified v4 from CDN. Set DX_HTMX_VERSION="2" to pull in v2. For prodution you likely want to serve your own minified htmx.js.

As there are significant syntax changes between v4 and v2 of htmx, keep DX_HTMX_VERSION in sync with what htmx version you are serving.

Configuration

In your settings file you can overide the following default values for Djxi:

  • DX_HTMX_VERSION": "4" # Choose between 4 and 2
  • DX_HTMX_MINIFIED": False # Load a minified source, recommended for production

Quick start

Create and manage your HTMX Endpoint in a convenient Battery:

from djxi.actions import DxActionRouter, dx_route

INLINE_TEMPLATE = """
<dx-section name="confirm-button">
    <button hx-post="/showcase/simple/confirm">
        Confirm, {{ name }}
    </button>
</dx-section>

<dx-section name="check-confirmed">
    <button disabled>Confirmed!</button>
</dx-section>
"""

class SimpleInlineActionRouter(DxActionRouter):
    inline_template = INLINE_TEMPLATE
    
    @dx_route("get-confirm-button", methods=["GET"])
    def get_confirm_button(self, request):
        context = {"name": "Phil"}
        return self.render_section(
            request, section_name="confirm-button", context=context
        )

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

djxi-0.1.3.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

djxi-0.1.3-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file djxi-0.1.3.tar.gz.

File metadata

  • Download URL: djxi-0.1.3.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for djxi-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a33fe5dd614a8fd8d8770d649e9867545a383247de1c9e09fdef00388da7d09b
MD5 a4ae9011a46c0f55bd63b519e20619e6
BLAKE2b-256 4acd62411ed57f19b3a15f812c5a689f0755e9031e36c42d7e3ad9b86eb9c436

See more details on using hashes here.

Provenance

The following attestation bundles were made for djxi-0.1.3.tar.gz:

Publisher: main.yml on rollinger/djxi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djxi-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: djxi-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for djxi-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9aeb55e7797a148c45089ec1f81ec6b0219f6b96350784361baf52ef8b0887ee
MD5 cf3a31471e5f6b7f47df54df85d4577b
BLAKE2b-256 02585b1de5bf2a163cf1c2758e4bdffe97f481d1d8f1910f17bb24e7050b501e

See more details on using hashes here.

Provenance

The following attestation bundles were made for djxi-0.1.3-py3-none-any.whl:

Publisher: main.yml on rollinger/djxi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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