Djang循环迭代中的单打印语句

2024-05-29 02:58:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Django模板,在循环迭代期间需要打印一次我的语句。我试过{% ifchanged %},但在两个循环中都不起作用。你知道吗

使用{% ifchanged %}可以在单个循环下工作,但我正在两个循环中尝试。你知道吗

例如:

{% for i in j %}
    {% for k in j %}
        {% ifchanged %}
            //something here//
        {% endifchanged %}
    {% endfor %}
{% endfor %}

然而,在这种情况下,它不起作用。你知道吗


Tags: djangoin模板forhere情况语句something
1条回答
网友
1楼 · 发布于 2024-05-29 02:58:06

还有forloop.first。你知道吗

请参阅the Django Built-in template tags and filters documentation,以获取与forloops相关联的变量。你知道吗

{% if forloop.first %}
    // something here //
{% endif %}

还有一个forloop.last,如果它需要显示在末尾,还有一个forloop.counter。你知道吗

相关问题 更多 >

    热门问题