如何在Django模板中拆分长行?

var*_*lon 18 django django-templates

我在Django模板中排队太长了

 {% for some_item, some_another_item, again_some_another_item_with_long_name in items %}
Run Code Online (Sandbox Code Playgroud)

我该怎么分裂呢?

使用\或仅拆分不起作用.

jul*_*ria 8

如果你真的想保留那些讨厌的长名字,我会做的是:

{% for a, b, c in items %}
    {% with a as some_item %}
    {% with b as some_another_item %}
    {% with c as again_some_another_item_with_long_name %}
        bla bla bla ..
    {% endwith %}
    {% endwith %}
    {% endwith %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,这可能是解决方法.但我更喜欢使用字典列表重写代码. (2认同)