1

I read this and my code looked like this:

html:

<li {% if request.path == '/groups/{{ group.id }}/' %}class="active"{% endif %} ><a href="{% url 'detail' group.id %}">Link</a></li>

The only problem is that /groups/{{ group.id }}/ obviously turn into:

/groups/{{ group.id }}/

not

/groups/1/

that will end up being a lot of code if type it for the other 10 links on the page.

Community
  • 1
  • 1
DrevanTonder
  • 726
  • 2
  • 12
  • 32

1 Answers1

4

Instead of hardcoding the url, use the url tag with as

{% url 'my_group_url_name' group.id as group_url %}
{% if request.path == group_url %}
Sayse
  • 42,633
  • 14
  • 77
  • 146