Skip to main content

Django Flex Menu

Github Build Github Tests codecov GitHub GitHub last commit

A flexible menu management system for Django built around anytree.

Features

  • Modular, tree-based design for easy customization and extension
  • Flexible URL resolution
  • Object-based processing for detail view menus
  • Thread-safe processing for concurrent requests
  • Request-specific menu state isolation
  • Simple template system with single template attribute per component
  • Child type validation for theme-specific menu classes

Installation

API

Once you have a menu instance, you can modify it in the following ways:

main_menu = Menu("Site Menu")
child_menu = MenuLink("My Child", url="/my-child")

# Append a child
main_menu.append(child_menu)

# Get a child instance by name
child_menu = main_menu.get("My Child")

# Pop a child (note this is done via the child menu, not the parent menu)
child = child_menu.pop()

# Extend a menu with a list of menu items
main_menu.extend([child_menu, child_menu2, child_menu3])

# Insert child/children at a specific position
main_menu.insert(child_menu, 2)

# Insert child after another named child
main_menu.insert_after(child_menu, "My Other Child")

Configuration

Logging URL Resolution Failures

By default, URL resolution failures are only logged when DEBUG=True. To control this behavior:

# In your Django settings
FLEX_MENU_LOG_URL_FAILURES = False  # Disable logging (recommended for production)
FLEX_MENU_LOG_URL_FAILURES = True   # Always log failures
# Default: settings.DEBUG

See CONFIGURATION.md for detailed configuration options.

Performance Considerations

For optimal performance in production:

  • Avoid menu.copy() during request processing - it's expensive
  • Cache permission checks when possible - use @lru_cache or Django's cache framework
  • Pre-resolve static URLs during app startup for menus that don't change
  • Use lazy evaluation - check parent visibility before processing children
  • Consider menu depth - deep hierarchies can impact performance

See PERFORMANCE.md for detailed optimization strategies.

Thread Safety

⚠️ Important: The menu processing is now thread-safe for concurrent requests. Each request gets its own processed copy to prevent race conditions.

See THREAD_SAFETY.md for detailed information about concurrency handling.

Theme-Specific Menu Classes

Create type-safe theme-specific menu classes:

class Bootstrap5DropdownMenu(Menu):
    template = "bootstrap5/dropdown-menu.html"
    allowed_children = ['Bootstrap5DropdownMenuLink']

class Bootstrap5DropdownMenuLink(MenuLink):
    template = "bootstrap5/dropdown-item.html"

# Type validation prevents mixing incompatible components
dropdown = Bootstrap5DropdownMenu("User Menu")
dropdown.append(Bootstrap5DropdownMenuLink("Profile", view_name="profile"))  # ✅ OK
dropdown.append(MenuLink("Settings", view_name="settings"))  # ❌ TypeError!

See THEME_CLASSES.md for detailed examples and patterns.

See also

django-account-management

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_flex_menus-0.4.3.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

django_flex_menus-0.4.3-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file django_flex_menus-0.4.3.tar.gz.

File metadata

  • Download URL: django_flex_menus-0.4.3.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_flex_menus-0.4.3.tar.gz
Algorithm Hash digest
SHA256 26a6f0d627c8e6108041cfc1f997bd09d130b86ab07ace78349f6dbe312e3417
MD5 dd330b30ddbdc225631c194160b592af
BLAKE2b-256 33292af8c487d4a0d7af786a403d9850294d1b44a38f133e8892f12e14a470a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_flex_menus-0.4.3.tar.gz:

Publisher: on-release-main.yml on django-mvp/django-flex-menus

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_flex_menus-0.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_flex_menus-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 35de7cdbc3d7798ac35cd661f87b0197bcaba35f5f5bd62732ab3654d9f9f534
MD5 7b96426e36631b568b24972344aaa48c
BLAKE2b-256 225a3204c5601c05cee7c80f99419b8149943cbe44962d32e6b5b40685f9b88d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_flex_menus-0.4.3-py3-none-any.whl:

Publisher: on-release-main.yml on django-mvp/django-flex-menus

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

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page