My django based website will have 3 seperate menus. The items of first one are: contact, about, disclosures. The second one will have: terms and condtions, privacy policy, copyright. And items of main menu are: Home, link1, link2, link2…. The first two menus will have fixed items, and the items of last one may change. As I will be using forloop in the template, what is the best approach for creating those menus. The webpages will have just a title and content.
Share
I like to use inclusion template tags for dynamic menus.
In
my-app/templatetags/myappmenu.py, I have something like:Then, in your template you can loop over the items and produce the menu in the format you desire (
<p>,<ul>, etc.).If you need to make items in the menu appear conditionally, you can add them to the list by checking permissions in the template tag; just pass the request or user object as argument to the template tag function.