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.2.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.2-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dj_layouts-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 82c69354a5471a7f8b9a58200dda949e1a728e99c284faace1e50409f6f4e182
MD5 64c83e86317c0f5837f151b55c39c2a4
BLAKE2b-256 4b179642e3db849d36d236a8c9752b97864ee5a3f59be2c209d7e8c3a194be1f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dj_layouts-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f280f4a4e67161ad899b83687cec06373822ccd86afd757e6292d3ffee6caa06
MD5 935ba293b2c1ebc5314634ff0bf129e3
BLAKE2b-256 9fef19bf65676aca6209dd6fef560a49d126b531e70801f75a2a021a5a111741

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