How to create a dynamic menu structure using Django?

I need a menu structure with menus and submenus, and depending on which page is currently being viewed, I want to highlight elements in both menus. Are there any modules or applications that provide this? If not, what would be the best way to approach the problem?

+4
source share
2 answers

A quick google search gives this:

http://code.google.com/p/django-treemenus/

http://code.google.com/p/django-menuse/

You can also create such a simple menu manually, just go to the template for the list of menu items, the active menu and the list of submenu items for the active menu and the active submenu item:

     <ul>
     {% for item in menu_items %}
         <li>
         {% if item.id == active_menu_item %}
             <span class="active-menu-item">{{ item }}</span>
             <ul>
                   {# Similar code for submenu items #}
             </ul>
         {% else %}
             <a class="inactive-menu-item" href="{{ item.url }}">{{ item }}</a>
         {% endif %}
         </li>
     {% endfor %}
     </ul>
+5

djangopackages, 2018 django-sitetree.

, django-activeurl.

django-sitetree .

, : modified preorder tree traversal, .

django-mptt (, ). django-mptt-admin, . contenttypes ( django-mptt).

0

Source: https://habr.com/ru/post/1772996/


All Articles