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

时间:2011-11-10 09:48:09

标签: django django-templates

我在Django模板中的行太长了

 {% for some_item, some_another_item, again_some_another_item_with_long_name in items %}

我该如何拆分它?

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

2 个答案:

答案 0 :(得分:7)

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

{% 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 %}

答案 1 :(得分:-1)

你可以使用'自动换行'或者'软包裹'文本编辑器的功能。 在PyCharm中,如果您按soft进行搜索,则会看到:

enter image description here