내 장고 템플릿 중 하나에서 목록을 반복 할 때 '만약 마지막 항목의'값 '값이 현재와 같은 경우'논리를 말할 것입니다. 항목의 'type'값을 루프하지만 그 일을위한 파이썬 구문이 장고 템플릿에서 허용되지 않는 것 같습니다. {{forloop.counter}}를 사용할 수는 있지만 해당 목록을 사용하여 특정 색인의 항목을 가져올 수는 없습니다.Django - django 템플릿 iterable에서 항목을 가져 오기
HTML
{% for repair in repairs %}
{% if repairs[{{ forloop.counter - 1}}].type == repair.type %}<div class="col-sm-12" style="border-top: 1px solid grey; border-bottom: 1px solid grey;"><h2>{{ repair.type }}</h2></div>{% endif %}
<div class="col-sm-6">
<label>
<input type="checkbox" name="{{ repair }}">
{{ repair }}</label>
</div>
{% endfor %}
또는 코드 여러 문제가 있습니다 또한
{% for index, repair in enumerate(repairs) %}
{% if repairs[index - 1].type == repair.type%}<div class="col-sm-12" style="border-top: 1px solid grey; border-bottom: 1px solid grey;"><h2>{{ repair.type }}</h2></div>{% endif %}
<div class="col-sm-6">
<label>
<input type="checkbox" name="{{ repair }}">
{{ repair }}</label>
</div>
{% endfor %}
/1.9/howto/custom-template-tags/ –
내가 아는 한, 장고의 템플릿 구문은'list [index]'를 지원하지 않고'list.index'를 대신 지원합니다. – Justin