Introduction

What is Djxi?

Djxi is a small utility library that helps you build “sectioned” Django templates and lightweight class-based endpoints that render individual named sections. It is designed to pair nicely with HTMX-style interactions: each section can be rendered independently and swapped into the page via hx-attributes.

Why use Djxi?

  • Keep your UI modular: split complex templates into named sections and render only the parts you need.

  • Bundle related view logic, URLs and templates in a single class to keep Locality of Behaviour and reduce the scattering of snippets across the codebase.

  • Integrates tightly with Django: messaging, template loading, and standard request/response semantics are preserved.

Key ideas

  • An “Endpoint Battery” (DXEndpointBattery) bundles the templates (inline or file-based), the URL definitions and the handler methods for a single feature.

  • Templates are split into named sections with a custom tag (default <dx-section name=”…”>) and can include other sections using <dx-include name=”…”/>.

  • Handlers are small methods decorated with @dx_action or the method shortcuts like @dx_get, @dx_put, etc. DXRouterMixin.url_patterns() turns these into Django paths you can include in your project’s URLConf.

Quick example

A minimal inline example (extracted from the project’s README):

from djxi import DXEndpointBattery, dx_action

INLINE_TEMPLATE = """
<dx-section name="todo-list-container">
    <div id="todo-list-container">...<dx-include name="todo-list"></div>
</dx-section>
"""

class SimpleInlineActionRouter(DXEndpointBattery):
    inline_template = INLINE_TEMPLATE

    @dx_get("list", name="list")
    def list(self, request):
        return self.render_section(request, section_name="todo-list-container")

Read the rest of the docs for installation instructions, configuration options and a hands-on tutorial that walks you through the included todo example.