Skip to main content

Django HTMX Integration

Project description

Djxi | HTMX Integration for Django

pre-commit

CI 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 not yet published and considered in experimental pre-alpha state.

  • 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.2.tar.gz (12.7 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.2-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djxi-0.1.2.tar.gz
  • Upload date:
  • Size: 12.7 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.2.tar.gz
Algorithm Hash digest
SHA256 8fb316fb6eb98b6e9dbfa8fcb19ebaf1ca1ccd50d355d7122569c6e956788481
MD5 eb18d751d40b0ef1e0d0d533250bb1d1
BLAKE2b-256 3eca7026e5c2644aa4f263f8c6075227614ff455e7bc726267065b3f4d8a2cc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for djxi-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: djxi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 09723ec2d85350a54e80d9211c333778203b6cac2229899270ce4ec0dc17f1df
MD5 b782834027b74e7f573ec69756b1aa37
BLAKE2b-256 cdc844c28865ce3dbda7c8d6579fe07f32f6b890699aef8157ef557ba5927f59

See more details on using hashes here.

Provenance

The following attestation bundles were made for djxi-0.1.2-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