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

查看:18
本文介绍了如何打破“for循环"在 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.

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

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循环"在 Django 模板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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