[英]How to create a global variable in django template?
I'm doing a loop inside my template, well, i want verify if my actual object is equal the object that comes before this. 我正在模板中进行循环,那么,我想验证我的实际对象是否等于之前的对象。
This is my tamplate code: 这是我的模板代码:
{% for i in format_data %}
<li>
{% with first=i %}
{{forloop.counter}}
{% if forloop.counter == 1 %}
<table class="format-table">
<tr>
<td data-format-id="{{i.format_name.id}}">{{i.format_name}}</td>
<td>{{i.field_name}}</td>
{% if i.field_format_data %}
<td>{{i.field_format_data}}</td>
{% else %}
<td>Campo não preenchido</td>
{% endif %}
</tr>
</table>
{% elif second == first %}
<table class="format-table">
<tr>
<td>{{i.field_name}}</td>
{% if i.field_format_data %}
<td>{{i.field_format_data}}</td>
{% else %}
<td>Campo não preenchido</td>
{% endif %}
</tr>
</table>
{% endif %}
{% endwith %}
{% with second=i %}
{% endwith %}
</li>
{% endfor %}
What I want is set a variable in the final of the loop that receive this actual object and in the next time that loop works, verify if the actual object is equal the last 我想要的是在接收该实际对象的循环的最后设置一个变量,并在下次该循环工作时,验证实际对象是否等于最后一个对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.