Django模板中的循环数值 [英] Numeric for loop in Django templates
本文介绍了Django模板中的循环数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Django模板中为循环编写数字?我的意思是像
How do I write a numeric for
loop in a Django template? I mean something like
for i = 1 to n
推荐答案
我使用了一种简单的技术,对于没有特殊标签的小案例而言,没有其他上下文。有时候,这可以很方便
I've used a simple technique that works nicely for small cases with no special tags and no additional context. Sometimes this comes in handy
{% for i in "xxxxxxxxxxxxxxxxxxxx" %}
{{ forloop.counter0 }}
{% endfor %}
根据您的需要调整xxxxxxxxxxxxxxxxxxxx的长度。 xxx只做3次迭代等。
Adjust the length of "xxxxxxxxxxxxxxxxxxxx" according to your needs. "xxx" to just do 3 iterations, etc.
这篇关于Django模板中的循环数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文