【问题标题】:Django template vars and list indicesDjango 模板变量和列表索引
【发布时间】:2011-10-20 20:03:54
【问题描述】:

我有一个奇怪的问题。

我使用分页器在每个页面中显示一些数据,但是,我看不到任何向模型添加我需要的其他属性的可能性,因此我创建了另一个包含其他数据的字典列表。

在模板中:

{% for x in p.object_list %}

{% with c=forloop.counter0 %}

    {{ info.c }} <!-- prints nothing, while {{ info }} prints all the list of dicts and {{ c }} prints 0, for example. {{ info.0 }} prints everything as intended too. -->

{% endwith %}

{% endfor %}

【问题讨论】:

    标签: django templates variables


    【解决方案1】:

    {{ info.c }} 访问 info['c']info.c 等。您需要 slice 过滤器。

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 2012-11-26
      • 2015-05-25
      • 1970-01-01
      • 2011-06-06
      • 2021-06-19
      相关资源
      最近更新 更多