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 PyPI - Django 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 DXEndpointBattery 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 DXEndpointBattery, 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(DXEndpointBattery):
    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.4.tar.gz (15.3 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.4-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djxi-0.1.4.tar.gz
  • Upload date:
  • Size: 15.3 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.4.tar.gz
Algorithm Hash digest
SHA256 2418c97326d864a9dcd27c3394f7835fae28d3b71bd38639f69b4a3ea90e9d63
MD5 67ac5205662e6d4df1779911aea1691b
BLAKE2b-256 6ed481b4abd46c1c6c05135452072c4ab1afe0971802cba7f88e63d7e80beff9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: djxi-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 17.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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8020a65df72e51c9f18493dcdacf107cb30fc7ddc0e8c4ab24cd1a4ba17133fd
MD5 9452b9241554b7539e661fd2752dc717
BLAKE2b-256 4b89a5afafc2cbdd0c9a08c0b6b6f34747e47ec38195a6c43ff0d841ca826e3e

See more details on using hashes here.

Provenance

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