Source

django-menus

django-menus is an app that provides some useful template helpers for rendering and handling menus within django projects.

To use in in your django project, it needs to be installed:

$ pip install -E /path/to/your/venv django-menus

And "menus" needs to be in your settings.INSTALLED_APPS.

menu_item

An inclusion template tag that will create a single instance of a menu item, which will only be rendered if the logged in user can access the referenced view. Secondly, the currently active view will have a CSS class of active in it's menu item.

Using the standard template. If you want, you can override the menus/item.html template to change the display format.

You may also pass in a string like "url:foo_name" to the first argument. This will do a reverse('foo_name') call (with no args or kwargs) to find a matching url.

If the menu item title is 'home' (case insensitive), or the url path is '/', then an exact match will be required to mark it as active, otherwise a prefix match is done. This means that if you had a menu item as above, and were viewing the url /foo/bar/, then the first menu_item would be marked as active.

tree_menu

An extension to django-mptt, this is a template that you can use to have a dynamic tree menu, where selecting items with children expands them, and selecting a leaf node follows the link. To use it, you'll need to have mptt installed into your project as well as this package.