【发布时间】:2017-09-10 21:22:42
【问题描述】:
我有这个代码
{% for time in listOfTimes %}
{% for booking in someOtherList.forloop.parentloop.counter0 %}
{{ booking }}
{% endfor %}
{% endfor %}
booking 变量未打印。我认为这是因为我无法使用forloop 计数器访问someOtherList。我如何获得booking 值?
【问题讨论】:
-
您想通过父循环
listOfTimes的索引值从someOtherList访问预订? -
没错。
-
你真的应该改变你的 Django 视图并构造上下文,这样逻辑就不会出现在模板之外。创建一个包含所有相关时间数据的字典列表,或者做一些事情来使循环内的循环变得微不足道。
标签: python django web django-templates