Skip to main content
Django Pythonic Menu
--

This is a simple library to help with building and working with site menu in your way.

It solves one issue: list available menu items and toggle some of them active.
Then pass it to template. With menu levels if you wish. In readable way.

Usage is following:
```python
# 1. Define the menu
class AppMenu(Menu):
first_menu_item = MenuItem('first_route')
another_menu_item = MenuItem('another_route', title="Some title", and_other_value_passed_to_template='Yea!')

class SubMenu(Menu):
subitem = MenuItem('subitem_route')

class Meta:
visibility = lambda request, item: request.user.is_authenticated
other_view_data = 'goes here'

# 2. Then activate it:
@AppMenu.first_menu_item.activate
def my_view(request):
pass
```

```html
# 3. Then render it in view as you like it:
{% load pythonic_menu %}
{% render_menu 'path.to.AppMenu' menu %}

{% for item in menu.items %}
<a href="{{ item.url }}" {% if item.active %}class="active"{% endif %}>{{ item.title }}
{{ item.and_other_value_passed_to_template }}</a>
{% endfor %}
```
Extra abilities:
==
* Submenus (just define another Menu inside Menu).
* Visibility checking (provide `visibility=lambda request, item: request.user.is_staff` argument).
* Ability to provide callbacks for urls (just pass `callback(request, item)`).
* Ability to cache & validate routes (call `Menu.cache_routes()` in your `App.ready()` method.

Goals
==
Main goals are:
* This is static menu written in Python. So no models/DB.
* Simple way to be mark active items. Just add decorator to your views. Also it's bound to menu definition so existence of items is checked on app start.
* No restrictions on view: you have {url: , title: , active: ) from library. Everything other is yours: add icon=.., className=.. etc as you like.
* Rendering menu is project-specific so it's your responsibility to make template for it.

Feedback
==
If you have any ideas/questions post either issue or pull request.

If you use it and found useful then write me a message or make a pull request to change alter this page.

Metadata

Release files for django_pythonic_menu 0.0.6

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_pythonic_menu 0.0.6
File Size Uploaded Provenance Actions
django_pythonic_menu-0.0.6.zip 11.7 kB Without provenance Details for django_pythonic_menu-0.0.6.zip

Release files / django_pythonic_menu-0.0.6.zip

Download URL django_pythonic_menu-0.0.6.zip
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
92cdfd6d30b96fea8a1028914e2e5ebec6ddb1db1dac47bf915c2eeb2944a48c
BLAKE2b-256 checksum
How to use checksums
29699376dd6333d3ac7050717dc47c6c7fa4b3f4743c5ad6e3f52d50cfb9e096
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django_pythonic_menu 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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