Hafiz
Hafiz

Reputation: 4267

strange comparison error in django template

Following is the part of my template that is having problem.

<select id="country" name="country_id">
        {% for country in countries%}
        {{country.id}} {{country_id}}
         {% if country.id==country_id %}
        <option value="{{ country.id }}"  selected="selected"  >
        {%else%}
        <option value="{{ country.id }}" >
         {%endif%}
            {{ country.name }}
        </option>
        {% endfor %}
    </select>

It gives error on this line: {% if country.id==country_id %}. Following is the error shown:

Could not parse the remainder: '==country_id' from 'country.id==country_id'

For me it is very strange that it is giving error on simple comparison statement. I also tried ifequal statement but that also didn't serve the purpose. What is the cause of this this problem and how can I solve it?

Upvotes: 0

Views: 49

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239290

You just need spaces around the ==, i.e.:

{% if country.id == country_id %}

Upvotes: 4

Related Questions