When a navigation link is clicked and page is redirected to that link, I am trying to highlight the active link in the nav bar. I was able to achieve the highlighting by using if and else. But I would like to know is there any way better than this. Right now I have to duplicate this code again and again.
<li class="nav-item"> <a {% if request.path == '/register' %} class="active nav-link" {% else %} class="nav-link" {% endif %} href=" {% url 'register' %} "> Register </a> </li>