My answer isn't 100% complete but what I have so far. What I am working on is having images displayed based on the site
I created nav.py looks like this below
nav = [
{'name': 'Home', 'url': '/'},
{'name': 'About', 'url': 'about'},
# {'name': 'pycURL', 'url': 'pythoncurl'},
{'name': 'Contact', 'url': 'contact'},
# {'name': 'cartest', 'url': 'bob'},
# {'name': 'socialtest', 'url': 'social'},
{'name': 'Search', 'url': 'search'},
# {'name': 'Searchtest2', 'url': 'search2'},
{'name': 'layouttest', 'url': 'layouttest'},
# {'name': 'Login', 'url': 'userauth'}
]
I then import nav into views.py and add to each route (I have not tested yet with out nav added to every route)
@app.route('/social')
def social():
"""Renders the about page."""
return render_template(
'social.html',
title='socialicons',
year=datetime.now().year,
message='test',
#import nav
nav=nav
)
Then in layout.html I call nav in a for loop
<ul class="nav navbar-nav">
{% for link in nav %}
<li><a href="{{ link.url }}" class="btn-large">{{ link.name }}</a></li>
{% endfor %}
</ul>
I extend layout.html to all of the pages I want the layout applied with
{% extends 'layout.html' %}
at the top of the page
When I want to add a new link to nav pretty much copy and paste a new line and change things to match the new route and it will apply to every page.
Why I answered this question is because what I am doing right now is working on something like what you are wanting but I want to make it work in a similar system. My goal is to apply different images to the navbar dynamically based on the page.