Answer the question
In order to leave comments, you need to log in
How to reuse navigation div on all pages?
There is a navigation block on the site:
<nav class="navigation block">
<a class="nav-link active" href="/">Главная</a>
<a class="nav-link" href="/xxx">xxx</a>
<a class="nav-link" href="/yyy">yyy</a>
<a class="nav-link" href="/zzz">zzz</a>
</nav>
Answer the question
In order to leave comments, you need to log in
Well, in general, Roman answered in the comments on the case, except that I would recommend checking the substring, since request.path can contain a nested directory, for example, and the check is in the spirit if '/' in request.path
(I don’t remember exactly if Jinja2 can do such checks, but if that you can write a function).
But there will be another problem, that there are paths that partially coincide, then the check will be done in both cases, so IMHO, it's better to raise it from a template that inherits or directly from a function that starts rendering an identifier, the check of which will be in the template in this navigation.
Let's say in routes:
...
render_template('template', current='home')
<nav class="navigation block">
<a class="nav-link {% if current == 'home' %}active{% endif %}" href="/">Главная</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question