Skip to main content

An extensible, hierarchical, and pluggable navigation system for Django sites.

django-treenav was designed from the start to live independent of a CMS implementation. As a separate application, treenav can easily be integrated into existing, custom setups and does not enforce or require users to use a particular content management system.

Sharing the same principles, django-pagelets integrates seamlessly with treenav and can be used together to create a flexible CMS product.

For complete documentation checkout, http://django-treenav.readthedocs.org

Features

  • Generic functionality with multiple URL specifications: get_absolute_url(), reverse(), or raw URLs

  • Packaged with templates to render the tree hierarchy with nested <ul>’s, but can easily be overridden with custom templates

  • Easily customize each item’s template or fall back to a default menuitem.html

  • Useful CSS classes for flexible UI customization

  • Automatically sets “active” on item and item’s parents if PATH_INFO is equal to item.href

  • Efficient: minimizes database access with django-mptt functionality

  • Caches the tree so that repeated page views do not hit the database.

  • Simple links in the MenuItem list view for refreshing the cache and href from the database.

Requirements

Using the demo

For a quick demo, follow these steps:

  1. Create a virtualenv. (This example uses mkvirtualenv, but there are many other ways to do it):

    $ mkvirtualenv django-treenav
  2. Check out the code and install the requirements:

    (django-treenav)$ git clone git://github.com/caktus/django-treenav.git
    (django-treenav)$ cd django-treenav/
    (django-treenav)~/django-treenav/$ pip install -Ur dev-requirements.txt
  3. Run migrations and create a superuser so you can login to the Django admin:

    (django-treenav)~/django-treenav$ python manage.py migrate
    (django-treenav)~/django-treenav$ python manage.py createsuperuser
  4. Run the server:

    (django-treenav)~/django-treenav$ python manage.py runserver
  5. Visit http://localhost:8000/ in your browser and follow the instructions.

Installation

  1. Install the app with pip:

    pip install django-treenav
  2. Add to your INSTALLED_APPS and run migrate:

    INSTALLED_APPS = (
        ...,
        'mptt',
        'treenav',
    )
  3. Include these context processors:

    TEMPLATES = [
      {
        'OPTIONS': {
          'context_processors': [
            "django.template.context_processors.request",
            "treenav.context_processors.treenav_active",
          ],
        },
      },
    ]
  4. Add these urls:

    urlpatterns = [
        url(r'^treenav/', include('treenav.urls')),
    ]

Maintainer Information

We use Github Actions to lint (using pre-commit, black, isort, and flake8), test (using tox and tox-gh-actions), calculate coverage (using coverage), and build documentation (using sphinx).

We have a local script to do these actions locally, named maintain.sh:

$ ./maintain.sh

A Github Action workflow also builds and pushes a new package to PyPI whenever a new Release is created in Github. This uses a project-specific PyPI token, as described in the PyPI documentation here. That token has been saved in the PYPI_PASSWORD settings for this repo, but has not been saved anywhere else so if it is needed for any reason, the current one should be deleted and a new one generated.

As always, be sure to bump the version in treenav/__init__.py before creating a Release, so that the proper version gets pushed to PyPI.

Development sponsored by Caktus Consulting Group, LLC.

Release files for django-treenav 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-treenav 2.0.0
File Size Uploaded
django-treenav-2.0.0.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-treenav 2.0.0
File Interpreter ABI Platform
django_treenav-2.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 44.7 kB

Release files / django-treenav-2.0.0.tar.gz

Download URL django-treenav-2.0.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
40d1bbce1ed16a6ef24822abfa1fd9120f20e0ea76c1c36eb80bb73b0c8e7c42
BLAKE2b-256 checksum
How to use checksums
2c1f51b8c57bbcff868fd0540f7d9813f892437dc03ab11e585a87dc2af95320
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

Release files / django_treenav-2.0.0-py2.py3-none-any.whl

Download URL django_treenav-2.0.0-py2.py3-none-any.whl
Size 25.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f8ae1d5bacc8d6670abdd9d21bb165b0713eae282e835159766f1f32db072f52
BLAKE2b-256 checksum
How to use checksums
6fddcbe3d9c341f89b7ea25b64f9792be91df9ac7f5a28585eec3365ddbbcae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page