html - Django: Highlight current page in navbar -


in layout.html (sometimes called base.html) have navbar this:

    <li class="dropdown"><a href="{% url 'index' %}" >home </a></li>     <li class="dropdown"><a href="{% url 'house_list' %}">your houses</a></li>     <li class="dropdown"><a href="{% url 'agency_list' %}">agencies</a></li>     <li class="dropdown"><a href="/admin">admin</a></li>     <li class="dropdown"><a href="{% url 'logout' %}"><i class="fa fa-lock"></i> log ud</a></li>     <li class="dropdown"><a href="{% url 'login' %}"><i class="fa fa-lock"></i> log ind</a></li> 

i highlight current page in navbar done changing <li class="dropdown"> <li class="dropdown active">

is there way django insert active page user on? appreciated!

i'm using django 1.9 , python 3.5.

you can name of url (referenced in urlpatterns). set 'active' class if url matches.

{% url_name=request.resolver_match.url_name %} <li class="dropdown {% if url_name == 'index' %}active{% endif %}"    <a href="{% url 'index' %}" >home </a> </li> <li>...</li> {% endwith %} 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -