空块无法在循环内与endif一起使用

时间:2019-03-01 10:48:25

标签: django python-3.x for-loop django-templates

我正在建立一个仪表板,其中空白内容具有不同的视图,因此用户不会查看空白区域。

例如,在 for循环而没有 if块的情况下,它运行良好

 {% for dashboard in dashboard_list %} 


    some content

            {% empty %} no data {% endfor %}

现在

{% for todo in todo_list %}
                            {% if todo.complete %}{% else %} some content



                            {% endif %}  {% empty %} content when its empty  {% endfor %}  

它不起作用,并且没有显示“无数据”

1 个答案:

答案 0 :(得分:1)

当然,它不起作用... {% empty %}仅在todo_list中没有任何内容时才被调用,如果每次循环传递都不会返回任何东西,则不会被调用。

要解决该问题,您应该遍历一个已被过滤且不包含任何完整项目的列表。