如何打破“for loop”在Django模板
问题描述:
我有这个代码
{% for account in object_list %}
<tr>
{% for field, value in book.get_fields %}
<th>{{ field.verbose_name }}</th>
{% endfor %}
</tr>
{{ break }}
{% endfor %}
我想在第一次迭代后打破for循环。破解不起作用
I want to break the for loop after first iteration. break is not working
答
Django模板系统中没有 break
。 Django模板系统未使用 python 编程,但拥有自己的语言。
There is no break
in Django template system. Django template system is not programmed with python but with its own language.
根据您需要做什么,您可能会发现这个问题有用。否则,只需在 RequestContext
上的特殊字段上唯一的帐户 打印 HTML 。
Depending on what you need to do, you might find this question useful. Otherwise, just put the one and only account you are trying to print on HTML on a special field on your RequestContext
.