1

I am not sure whether I have discovered a bug, have my system misconfigured, or am just misunderstanding the {% cycle %} template tag in Django.

The manual provides the following sample code:

{% cycle 'row1' 'row2' as rowcolors silent %}{# no value here #}
{% for o in some_list %}
    <tr class="{% cycle rowcolors %}">{# first value will be "row1" #}
        ...
    </tr>
{% endfor %}

It clearly says that the first cycle declaration will output nothing, and the subsequent call will be the first iteration.

I am having the following issues: firstly, the second call outputs 'row2', which would be expected on the second call. Secondly, the subsequent {% cycle rowcolors %} calls don't output anything either!

Am I completely misunderstanding something, or does the tag not work as specified?

4

1 回答 1

1

据我所知,代码是循环函数的文档字符串与实际文档中的代码示例不同。您应该使用{{ rowcolors }}来显示循环文本。

其次,随后的 {% cycle rowcolors %} 调用也不输出任何内容!

从文档中:

在循环定义中使用静默关键字时,静默将自动应用于循环标记的所有后续使用。在中,即使对 {% cycle %} 的第二次调用没有指定静默,以下模板也不会输出任何内容:

该段后面的代码示例似乎与您当前的问题相似。

于 2012-09-09T03:42:17.523 回答