P
P
pavuuuk2020-05-30 11:22:39
Django
pavuuuk, 2020-05-30 11:22:39

Why is variable not visible inside if in django template?

I have a list of categories and a category id that are passed to a template. I need to display the title of the corresponding category on the page, but for some reason the comparison inside the for loop does not work. The if variable is not visible, but it is visible in the loop.

{% block content %}
<div class="wrapper">
  {% for c in categories %}
    <h1 class="title">
      {% if c.category_no = id %}
        {{c.name}}
      {% endif %}
    </h1>
  {% endfor %}
</div>
{% endblock content %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-05-30
@pavuuuk

There is no comparison in the code you provided. There is an assignment of the id variable to the category_no attribute.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question