如何打破“for loop”在Django模板 [英] How to break "for loop" in Django template

查看:91
本文介绍了如何打破“for loop”在Django模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码

    {% for account in object_list %}
        <tr>
        {% for field, value in book.get_fields %}
              <th>{{ field.verbose_name }}</th> 
        {% endfor %}
        </tr>
    {{ break }}
    {% endfor %}

我想在第一次迭代后打破for循环。破解不起作用

I want to break the for loop after first iteration. break is not working

推荐答案

Django模板系统中没有 break 。 Django模板系统未使用 python 编程,但拥有自己的语言

There is no break in Django template system. Django template system is not programmed with python but with its own language.

根据您需要做什么,您可能会发现这个问题有用。否则,只需在 RequestContext 上的特殊字段上唯一的帐户 打印 HTML

Depending on what you need to do, you might find this question useful. Otherwise, just put the one and only account you are trying to print on HTML on a special field on your RequestContext.

这篇关于如何打破“for loop”在Django模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆