Create Navbar In Django

Hi friends,
I have created dynamic navigation bar in website top menu using django admin panel to html template,

anyone please tell create navigation bar dynamically


thats (HOME ELEMENT,FEATURE, etc) create django admin panel then automatically display in menus

The simple answer here is “pull them from a model” - make a Django model for your navbar items with a “title” and “url” field, and feed it into the template, then loop over it like this:

{% for navbar_item in navbar_items %}
    <a href="{{ navbar_item.url }}">{{ navbar_item.title }}</a>
{% endfor %}

If you want to make sure that the navbar_items variable is included in every template render, you could do that using a Context Processor

Hey This work perfectly but this only show on only new page like this

Not showing in index.html page

i am include menus.html page in index.html page but not display navigation bar please help

It’s tough to know without seeing the code for each of the views. If I had to guess, the view for /menus/ queried whatever model stores the navbar items while the view for / does not.

As noted in the previous comment, if you want the data available in every view, you could create a custom context processor that would happen on every request.

Alternatively, you could create a custom template tag like an inclusion tag that can render the menu fragment.

I need Help 3 level Navigation menu
menu (if menu.parentId == Null)
------menu (if menu.parentId != Null and menu.parentId == menu.Id)
----------menu (if menu.parentId == menu.Id)

result id-parentId

Thank you