Answer the question
In order to leave comments, you need to log in
How to make an active link in Python?
Hello!
The template has the following menu code:
<ul class="nav nav-tabs">
<li><a href="{% url 'xxx' %}">Ссылка 1</a></li>
<li><a href="{% url 'yyy' %}">Ссылка 2</a></li>
</ul>
Answer the question
In order to leave comments, you need to log in
Correct solution! - determine in the view or model which link should be marked as active now
stackoverflow.com/a/9793609
App
https://github.com/hellysmile/django-activeurl
Found a solution here python.su/forum/topic/11194/?page=1#post-70900
in my case it looks like this:
<ul class="nav nav-tabs">
<li {%if 'xxx' in request.path %}class="active"{%endif%}><a href="{% url 'xxx' %}">Ссылка 1</a></li>
<li {%if 'yyy' in request.path %}class="active"{%endif%}><a href="{% url 'yyy' %}">Ссылка 2</a></li>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question