I started studying Flask with a site rework, where all pages are static. Now all page templates will be inherited from the main base template, which has the main menu of the site:
... <ul class="nav navbar-nav"> <li> <a href="{{ url_for('main.index') }}">Главная</a> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Услуги<b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="{{ url_for('main.projects_development') }}">Проекты освоения</a></li> <li class="divider"></li> <li><a href="{{ url_for('main.forest_regulation') }}">Лесоустройство</a></li> </ul> </li> <li> <a href="{{ url_for('main.contacts') }}">Контакты</a> </li> <li> <a href="{{ url_for('main.about_us') }}">О нас</a> </li> <li><a href="#">Вход</a></li> </ul> I faced the problem of selecting the menu item that corresponds to the active page; earlier the active class was added manually in the code itself, now it is necessary to define this class dynamically. So far, from ideas there is only the addition of an if block, which checks the entry of a string with a route into the value of request.url, that is, something like this:
<li {% if '/contacts' in request.url %}class="active"{% endif %}> Tell me, please, how to implement it correctly? How to check this condition for the route '/'? Or, in general, is it more correct to implement through JS?