【发布时间】:2012-05-23 05:47:04
【问题描述】:
假设我正在使用 .. 在模板内传递变量“小计”
在我看来.py
subtotal = 0
page_vars = Context({
'players': players,
'subtotal': subtotal,
})
在我的 html 中。
{% for player in players %}
{% subtotal += player.score %}
{{ player.name }} <td />
{{ player.score }} <td />
{% endfor %}
{{ subtotal }}
它给了我
无效的块标签:'subtotal',预期为 'empty' 或 'endfor'
我们不能在 django 模板系统中嵌套块标签吗?
如果是,怎么做?
必须有,至于我计算小计,我必须计算我的小计,我必须在两个地方运行相同的 for 循环,这使得它非常低效!
//鼠标。
【问题讨论】: