【问题标题】:How to get access to next object on demand in list in django template?如何在 django 模板的列表中按需访问下一个对象?
【发布时间】:2010-02-01 21:14:08
【问题描述】:

我认为这是新手问题。

我想遍历两个列表:第一个在 for 循环中,第二个在某些条件为真时。 在django模板中怎么做?

【问题讨论】:

  • 您的问题不清楚。你有两个列表,你想在你的模板中做什么?也许您可以将示例输出添加到您的问题中。

标签: django-templates


【解决方案1】:

我会尝试做简单的日历。

传说:
事件 - 带有事件对象的列表
月 - calendar.Calendar().monthdatescalendar() 列出来自 python 库的对象 timedate.date

{% for week in month %}
    {% for day in week %}
         {% if day < Events.0.startdate.date %}
              print something like <a href = "{{ Events.0.get_absolute_url }}">{{ day }} </a>
              increase Events

         {% else %}
              {{ day }}
         {% endif %}
    {% endfor %}
 {% endfor %}

【讨论】:

    猜你喜欢
    • 2021-04-18
    • 2011-04-19
    • 2021-10-17
    • 2015-08-18
    • 2010-12-01
    • 2011-06-05
    • 2021-01-06
    • 2013-01-16
    • 1970-01-01
    相关资源
    最近更新 更多