G
G
Googlus2016-02-06 10:45:34
Django
Googlus, 2016-02-06 10:45:34

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>

How to make it so that if the page /xxx/ is open, then class="active" is added to the link
Well, similarly, if you go to the page yyy, then this link already has class="active" ???

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-02-06
@sim3x

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

G
Googlus, 2016-02-06
@Googlus

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 question

Ask a Question

731 491 924 answers to any question