所以它似乎是重复的,但没有一个答案可以解决我的问题。
所以我正在使用基于分类的视图。 在上下文中,我发送的东西为active_country
{{active_country}} <select class="country-link inputText span5"> <option value="all">All Countries</option> {% for country in countries %} <option value="{{ country.country_code }}" {% if active_country == country.name %} selected="selected" {% else %} not working {% endif %}>{{ country.name }}</option> {% endfor %} </select>但if条件永远不会成真。 我甚至尝试过:
{% if active_country == "Australia" %} selected="selected" {% endif %}活跃的国家给澳大利亚,但仍然没有得到真实的条件。
我也尝试过:
{% ifequal active_country "Australia" %} selected="selected" {% endifequal %}我肯定知道active_country正在接收。 我也单独打印过。
任何人都可以提出错误吗?
So it may seem as a duplicate but none of the answers solve my issue.
So I'm using classed based views. In context I'm sending something as active_country
{{active_country}} <select class="country-link inputText span5"> <option value="all">All Countries</option> {% for country in countries %} <option value="{{ country.country_code }}" {% if active_country == country.name %} selected="selected" {% else %} not working {% endif %}>{{ country.name }}</option> {% endfor %} </select>But the if condition is never getting true. I even tried:
{% if active_country == "Australia" %} selected="selected" {% endif %}active country gives Australia but still condition does not get True.
And I have also tried:
{% ifequal active_country "Australia" %} selected="selected" {% endifequal %}I for sure know the active_country is being received right. I have printed it separately as well.
Can any one suggest whats wrong?
最满意答案
所以我回答了我的一个问题。 我犯的错误:
active_country是一个对象。 因此我应该使用active_country.name
我感到困惑,因为{{active_country}}也给出了名字。 这是因为在我的models.py中将unicode设置为name
So I'm answering my one question. The error I was making:
active_country is an object. Hence I should be using active_country.name
I was getting all confused as just {{active_country}} was also giving the name. This was because the unicode was set to name in my models.py
更多推荐
发布评论