2👍
You made a typo, this is the first thing to check when coding and specifically with django templates because unbound variables don’t raise an error.
cats.html
{% if cats %}
<ul class="nav nav-sidebar">
{% for c in cats %}
{% if c == act_act %} <li class="active"> {% else %} <li>{% endif %}
<a href="{% url 'category' c.slug %}">{{ c.name }}</a></li>
{% endfor %}
{% else %}
<li><strong>There are no category present.</strong></li>
</ul>
{% endif %}
cats
should be cat_list
. There is not act_act
variable passed to the template.
Also I recommend you avoid small variable names. Instead of cats
use categories
instead of act_act
use active
or better active_category
. Instead of c
which is not readable, use category
. This makes the code more readable not only because the names are longer but because you don’t require the cognitive load to translate terse/cryptic words to english.
I use plural names even with english words that pluralize with only an s
. This might sound prone to errors and typos but actually it’s ok, e.g. given the variable token
(and not tok
), I’ll name tokens
a list
or set
of token
.