django模板中的奇怪比较错误

时间:2012-08-22 15:11:03

标签: django django-templates

以下是我的模板中有问题的部分。

<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>

它在此行中出错:{% if country.id==country_id %}。以下是显示的错误:

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

对于过去遇到此问题的人来说,似乎很容易理解,但对我而言,它在简单的比较语句中给出错误是非常奇怪的。我也试过ifequal声明,但这也没有达到目的,所以我在这里知道为什么会出现这个问题,我该如何解决呢?

如果需要进一步的详细信息,请告诉我。谢谢你们。

1 个答案:

答案 0 :(得分:4)

你只需要==周围的空格,即:

{% if country.id == country_id %}
相关问题