3

I am making the navigation of the page as active by checking if the url matches with the current url.

<li>
  {% url 'blog' as blog_url %}
  <a href="{{blog_url}}" {% if request.get_full_path == blog_url %}class="active"{% endif %}>Blog</a>
</li>

Now I am using pagination, which when going to different page results in url being like this:

From /blog/ to

/blog/?page=2
/blog/?page=3

And the above code does not work. So is there anyway to use regex in the template to get anything (like /blog/*) and make it as active. Your help and guidance will be very much appreciated. Thank you.

Robin
  • 5,366
  • 17
  • 57
  • 87

1 Answers1

6

you can just do

{% if '/blog/' in request.path %}class="active"{% endif %}

no need for regexp

doniyor
  • 36,596
  • 57
  • 175
  • 260