Django模板循环。会员之前 [英] Django template for loop. Member before
本文介绍了Django模板循环。会员之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建这样的循环:
{% for object in objects %}
{% if object.before != object %}
{{ object }} this is different
{% else %}
{{ object }} this is the same
{% endfor %}
根据 https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for I不能。真的没有简单的方法吗?或者我只需要使用计数器并检查对象[counter-1]
?
Based on https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for I can't. Is there really no simple way to do this? Or I just need to use counter and check for objects[counter-1]
?
P.S。 .before
是理论,对象是简单的查询列表。我想在当前循环成员之前遇到的循环成员执行某些操作。
P.S. .before
is theoretical and objects is simple query list. I want to take and do something with the loop member that encountered before current loop member.
推荐答案
检查 ifchanged 模板标签
这篇关于Django模板循环。会员之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文