Skip to main content

A simple, flexible, and extensible navigation menu for Django.

Project description

django-simple-nav

PyPI PyPI - Python Version Django Version

Define your navigation in Python, render it in templates. django-simple-nav handles URL resolution, active state detection, and permission filtering so your nav stays in sync with your project.

Requirements

  • Python 3.10, 3.11, 3.12, 3.13, 3.14
  • Django 4.2, 5.2, 6.0

Installation

uv add django-simple-nav
# or
python -m pip install django-simple-nav

Add django_simple_nav to your INSTALLED_APPS:

INSTALLED_APPS = [
    # ...,
    "django_simple_nav",
    # ...,
]

Getting Started

Define your navigation in a Python file. items is what gets rendered, and template_name points to the template that controls the markup:

# config/nav.py
from django_simple_nav.nav import Nav
from django_simple_nav.nav import NavGroup
from django_simple_nav.nav import NavItem


class MainNav(Nav):
    template_name = "main_nav.html"
    items = [
        NavItem(title="Home", url="/"),
        NavItem(title="About", url="/about/"),
        NavGroup(
            title="Resources",
            items=[
                NavItem(title="Blog", url="/blog/"),
                NavItem(title="Contact", url="/contact/"),
            ],
        ),
    ]

Create main_nav.html. The template receives the items defined above — each has a title, url, active state, and groups have nested items:

<!-- main_nav.html -->
<nav>
  <ul>
    {% for item in items %}
      <li>
        <a href="{{ item.url }}"{% if item.active %} class="active"{% endif %}>
          {{ item.title }}
        </a>
        {% if item.items %}
          <ul>
            {% for subitem in item.items %}
              <li>
                <a href="{{ subitem.url }}"{% if subitem.active %} class="active"{% endif %}>
                  {{ subitem.title }}
                </a>
              </li>
            {% endfor %}
          </ul>
        {% endif %}
      </li>
    {% endfor %}
  </ul>
</nav>

Then use the template tag wherever you want the nav to appear. The string is the import path to your Nav class:

{% load django_simple_nav %}

{% django_simple_nav "config.nav.MainNav" %}

Examples

The example directory contains a simple Django project that demonstrates how to use django-simple-nav, including navigation definitions for a few different scenarios and some popular CSS frameworks.

git clone https://github.com/joshuadavidthomas/django-simple-nav
cd django-simple-nav
uv sync
uv run example/demo.py runserver

Then open your browser to http://localhost:8000.

Documentation

For the full documentation — including permissions, extra context, Jinja2 support, self-rendering items, and more — please visit the documentation site.

License

django-simple-nav is licensed under the MIT license. See the LICENSE file for more information.

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

django_simple_nav-0.15.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

django_simple_nav-0.15.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file django_simple_nav-0.15.0.tar.gz.

File metadata

  • Download URL: django_simple_nav-0.15.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_simple_nav-0.15.0.tar.gz
Algorithm Hash digest
SHA256 fc4b4f7216b58c77188c8a148723560e0bab404a8e6d5d57f2d37df3be93450b
MD5 3a2dc85f092843947c8eab00d92fdf9f
BLAKE2b-256 0812d5104416061fd74b136d5b2d88648b30368b48f198003e1b011fbae8ea15

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_simple_nav-0.15.0.tar.gz:

Publisher: release.yml on joshuadavidthomas/django-simple-nav

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_simple_nav-0.15.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_simple_nav-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67a9d71fe43379453cc02138fd80ba9f4435c2339e388a6d7413310eef2277c1
MD5 c32a8cd4367e6c0288f44dd1820b976e
BLAKE2b-256 e112a0282968f0759498aa1374bb4f9c5a0b0699c2d9dea4cc28dc246b515e2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_simple_nav-0.15.0-py3-none-any.whl:

Publisher: release.yml on joshuadavidthomas/django-simple-nav

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