Skip to main content

A Django layout composition library — assemble pages from independent views, rendered concurrently

Project description

dj-layouts

CI PyPI version Python versions Django License: MIT

A Django layout composition library. Views return their own content as partials; a Layout class assembles the full page by calling other views as named panels, concurrently under ASGI.

Read the docs →

Quick start

pip install dj-layouts
# myapp/layouts.py
from dj_layouts import Layout, Panel

class DefaultLayout(Layout):
    template = "layouts/default.html"
    navigation = Panel("core:navigation")
    footer = Panel("<p>© Acme</p>")
# myapp/views.py
from dj_layouts import layout

@layout(DefaultLayout)
def homepage(request):
    return render(request, "home/index.html", {"items": get_items()})

HTMX Smart Routing (SPA)

With HTMX Smart Routing, you can turn your standard multi-page Django application into a smooth single-page application (SPA) with zero client-side routing logic.

Opt-in by enabling the setting in your settings.py:

DJ_LAYOUTS = {
    "PARTIAL_DETECTORS": ["dj_layouts.detection.htmx_detector"],
    "HTMX_SMART_ROUTING": True,
}

Add hx-boost="true" to your <body>. When a user navigates between views:

  • If the next view uses the same layout, dj-layouts returns only the partial view response and tells HTMX to retarget and swap just the #panel-content panel (extremely fast).
  • If the next view uses a different layout, dj-layouts dynamically assembles the new full layout, updates the layout tracker cookie, and tells HTMX to smoothly swap the entire <body>.

Supported versions

Python Django
3.13 5.2 (LTS)
3.14 6.0
latest

Documentation

Full documentation at fukalite.github.io/dj-layouts/.

Contributing

See CONTRIBUTING.md.

Security

See SECURITY.md.

Licence

MIT

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

dj_layouts-0.0.3.tar.gz (96.5 kB view details)

Uploaded Source

Built Distribution

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

dj_layouts-0.0.3-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file dj_layouts-0.0.3.tar.gz.

File metadata

  • Download URL: dj_layouts-0.0.3.tar.gz
  • Upload date:
  • Size: 96.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dj_layouts-0.0.3.tar.gz
Algorithm Hash digest
SHA256 499ded9b1eebf891d93fefee3e45f8fa015b9fd3bc06875a9ae3b46cb316264a
MD5 fb12a08de1810f7cccc4e44ce3599fbc
BLAKE2b-256 3b2b7105b8fc45e67017bb50998d9e088cf7e6383a97912752efa4bb086ed886

See more details on using hashes here.

File details

Details for the file dj_layouts-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: dj_layouts-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dj_layouts-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7de7cda7fcbcc26336f7b37bdec3d9239cb6247ed194c4c9816559faa48a92dc
MD5 203173ff0c6f5036c8810a8cf2ab0953
BLAKE2b-256 b18be8f1729a93aee041b126e246178d5b15cc6a96f8ae5f068ff46d8a568ba6

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