Make navbar item active in Django Template
<p>i'm creating menu with forloop and i need to add active class after click. </p>

<pre><code>{% for menu in TopMenu %}
      &lt;li&gt;&lt;a href="/content/{{menu.slug_link}}"&gt;{{menu.title}}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<p>i tried to use django template inheritance but it didn't work. any solutions?</p>

<pre><code>{% for menu in TopMenu %}
      &lt;li {%if activeflag == '{{menu.slug_link}}' %} class="active"    {%endif%} &gt;&lt;a href="/content/{{menu.slug_link}}"&gt;{{menu.title}}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<p>You don't need <code>{{ }}</code> when using the <code>if</code> tag.</p>

<p>Try:</p>

<pre><code>{% if activeflag == menu.slug_link %} class="active" {% endif %}
</code></pre>

python django