How to check if, elif, else conditions at the same time in django template
<p>I have 3 category in category field. I want to check it in django template and assign appropirte urls for 3 distinct category.</p>

<p>I tried:</p>

<pre><code>{% for entry in entries %}
        {% if entry.category == 1 %}
        &lt;a href="{% url 'member:person-list' %}"&gt;&lt;li&gt;{{ entry.category }}&lt;/li&gt;&lt;/a&gt;
        {% elif entry.category == 2 %}          
        &lt;a href="{% url 'member:execomember-list' %}"&gt;&lt;li&gt;{{ entry.category}}&lt;/li&gt;&lt;/a&gt;
         {% else %}
         &lt;a href="{% url 'member:lifemember-list' %}"&gt;&lt;li&gt;{{ entry.category}}&lt;/li&gt;&lt;/a&gt;
        {% endif %}
{% empty %}
    &lt;li&gt;No recent entries&lt;/li&gt;
{% endfor %}
</code></pre>

<p>But I know python only check first matching condition with if. Therefore it gave only one desired result. How do I get all three entries with their correct links?</p>

<p><strong>Edit:</strong></p>

<p>Though python only check first matching if condition, when use elif within for loop it check each condition until endfor loop. Therefore my answer below worked fine. </p>

<p>This is my working answers:</p>

<pre><code>   {% for entry in entries %}
        {% if entry.category == 'General Member' %}
        &lt;a href="{% url 'member:person-list' %}"&gt;&lt;li&gt;{{ entry.category }}&lt;/li&gt;&lt;/a&gt;
    {% elif entry.category == 'Executive Committee Member' %}
        &lt;a href="{% url 'member:execomember-list' %}"&gt;&lt;li&gt;{{ entry.category}}&lt;/li&gt;&lt;/a&gt;
    {% else %}
    &lt;a href="{% url 'member:person-list' %}"&gt;&lt;li&gt;{{ entry.category}}&lt;/li&gt;&lt;/a&gt;
        {% endif %}
    {% empty %}
        &lt;li&gt;No recent entries&lt;/li&gt;
  {% endfor %}
</code></pre>

<p>Webpage view of output: </p>

<p><a href="http://i.stack.imgur.com/Tilua.png" rel="nofollow"><img src="http://i.stack.imgur.com/Tilua.png" alt="enter image description here"></a></p>

<p>For more clarifications, I check my code with the django shell. See the snippet of my shell: </p>

<p><a href="http://i.stack.imgur.com/NITIk.png" rel="nofollow"><img src="http://i.stack.imgur.com/NITIk.png" alt="enter image description here"></a></p>

<p>Even I change the order of if conditions, result remain the same. See my shell code with output:</p>

<p><a href="http://i.stack.imgur.com/wVJJs.png" rel="nofollow"><img src="http://i.stack.imgur.com/wVJJs.png" alt="enter image description here"></a></p>

<p>Do you see any wrong with my codes? Its fully comply with the python conditions and gives expected results. Anybody can check it on their django shell. </p>

python django