你需要的是
continue
. Continue允许您跳过该循环并转到下一个迭代。我不知道django语法。我只是遵循了其他格式。
{% for instance in questions %}
<div>
{% for field, value in instance.fields.items %}
<div class="slidecontainer">
Counter: {{ forloop.counter }}
{% if forloop.counter == 1 %}
{% continue %}
{% endif %}
<form name = "{{ field }}" id = "{{ field }}" >
{{ value }}<br>
<input class="slider" id="{{ field }}" input type="range" name="{{ field }}" min="0" max="10" value="5" step="1" onchange="showValue(this)" />
<span id="range">5</span>
</form>
</div>
{% endfor %}
</div>
{% endfor %}
与另一个相同,假设它处于for循环中。
{% if forloop.counter == 1 or foorloop.counter == 4 or foorloop.counter == 12 or foorloop.counter == 20 %} # and more, shortened
# show nothing - the parts of loop I am wanting to skip
{% continue %}
{% else %}
# show what I want for the other iterations of loop
{% endif %}