Registry / web-framework / flask-menu

flask-menu

JSON →
library2.0.0pypypi✓ verified 85d ago

Flask-Menu is a Flask extension that adds support for generating menus and navigation bars. Version 2.0.0 supports Python >=3.7, with a stable release cadence. It provides decorators and template helpers to define menus hierarchically and render them in templates.

pip install flask-menu
INSTALL
IMPORT
SIG · FLASK-MENU
F
flask-menu
web-frameworkpythonv2.0.0
Install
2.2s avg
Import
485ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.494s · 22.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.476s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Menu
from flask_menu import Menu
from flask.ext.menu import Menu
Flask-Ext pattern was removed in Flask 2.0
register_menu
from flask_menu import register_menu

Initialize the Menu extension and register a menu entry on a view function.

from flask import Flask from flask_menu import Menu, register_menu app = Flask(__name__) Menu(app) @app.route('/') @register_menu(app, '.index', 'Home', order=0) def index(): return 'Hello' if __name__ == '__main__': app.run()
Debug
Known issues
breakingVersion 2.0.0 removed the `Menu` class's `register_menu` method and uses the decorator `@register_menu` directly on view functions.
fix
Use the `register_menu` decorator instead of `Menu.register_menu`.
affects: >=2.0.0
breakingThe `active` key in the menu entry's attributes is no longer automatically set by the extension; you must use Jinja2 extensions to check current endpoint.
fix
Use `{% active_menu %}` or `current_menu` in templates to highlight active items.
affects: >=2.0.0
gotchaThe `register_menu` decorator must be placed above the route decorator, otherwise the endpoint might not be registered.
fix
Apply `@register_menu` before `@app.route`.
affects: >=2.0.0
Errors
Common errors & fixes
ImportError: cannot import name 'Menu' from 'flask.ext.menu'
Using the deprecated Flask-Ext import style.
fix
Use `from flask_menu import Menu` instead.
RuntimeError: The menu entry '...' is not registered because the endpoint '...' does not exist.
The decorator `@register_menu` is applied after the route decorator, or the view function is not defined.
fix
Ensure `@register_menu` is placed directly above `@app.route` and that the endpoint matches the route's endpoint.
Upgrade
Version history
2.0.0latest on PyPI · released Nov 21, 2024
Audit
Dependencies
FlaskrequiredRequired as the framework
Agent activity
4 hits · last 30 days
node
4
Resources
flask-menu — pip install flask-menu · libregistry