Main menu¶
Warning
The MainMenu
component is considered experimental. That means the API can change in breaking ways in minor releases of iommi. It also means you import from iommi.experimental
to make that clear.
The main menu component in iommi is used to create the main navigation for your app. This is primarily useful for SaaS or internal apps. It creates a sidebar menu with support for nested menu items, and centralized access control that automatically shows only menu items the user has access to.
To set up your main menu:
add the
iommi.experimental.main_menu.main_menu_middleware
middleware to theMIDDLEWARE
listdeclare your
MainMenu
define the
IOMMI_MAIN_MENU
setting to point to where you have defined your menu (likeIOMMI_MAIN_MENU = 'your_app.main_menu.main_menu'
).add the url patterns from the menu to your app
Access control is recursive, meaning that if a user does not have access to a menu item, it is automatically denied access to all subitems.
Note
There are many more examples in the cookbook.
menu_declaration = MainMenu(
items=dict(
artists=M(
icon='people',
view=artists_view,
),
albums=M(
icon='disc',
view=albums_view,
),
),
)
Add the url patterns from the menu to your app:
urlpatterns = menu_declaration.urlpatterns()
Your views will now get the menu rendered on standard iommi views. For non-iommi views you can render the menu with {{ request.iommi_main_menu }}
.