Django stringformat i

时间:2016-05-09 08:52:52

标签: django

我在页面上有一个下拉列表。当用户选择值时,选项的索引存储在数据库中。当用户检索页面时,默认情况下应选择先前存储的值。

这是我在模板中渲染所选选项的方式:

{% if report.tag == forloop.counter|stringformat:"i" %}
    selected="selected"
{% endif %}

for循环包含值列表,report.tag包含用户先前选择的值。

我的问题是:在比较模板中的值时,我必须使用forloop.counter|stringformat:"i"。如果使用forloop.counter,则比较将不起作用。那是为什么?

// if never registers, even though foorloop.counter 
// outputs the same value as forloop.counter|stringformat:"i"
{% if report.tag == forloop.counter %}  

0 个答案:

没有答案
相关问题