A Django project providing a flexible, hierarchical menu system as a reusable app.
- Unlimited nested menu levels
- Supports both named URL reversals and custom URLs
- Automatic active menu item detection
- Django admin integration for creating Menus and MenuItems
- Easily override templates and styles
- Clone the repository:
git clone https://github.com/PureEev/menu-system.git cd menu-system - Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # Unix/macOS venv\Scripts\activate # Windows pip install Django
- Run migrations:
python manage.py migrate
- (Optional) Create a superuser to access the admin:
python manage.py createsuperuser
- Start the development server:
python manage.py runserver
Visit http://127.0.0.1:8000/ in your browser to see the demo.
The menu app is already included in INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'menu',
]- Navigate to the Django admin at
/admin/. - Create a new Menu, giving it a unique name.
- Add MenuItems under that menu:
- Title: The display text.
- URL: Custom URL or named route.
- Named URL: Toggle if using Django's named URL reversing.
- Parent: Set to nest items.
- Order: Controls the display order.
Load and render your menu in any template:
{% load menu_tags %}
{% draw_menu 'Your Menu Name' %}This will include the following templates:
menu/menu.htmlmenu/menu_level.html
- Templates: Override by placing your own versions at
templates/menu/menu.htmlandtemplates/menu/menu_level.html. - CSS: Style the classes:
.menu-container.main-menu.sub-menu.active