Main menu¶
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.main_menu.main_menu_middlewaremiddleware to theMIDDLEWARElistdeclare your
MainMenudefine the
IOMMI_MAIN_MENUsetting 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 }}.