varepsilon
varepsilon

Reputation: 488

How to split long line in Django template?

I have a line in my Django template that is too long:

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

Is there a way to split it so that it looks nicer in the source code?

Using \ or just splitting doesn't work.

Upvotes: 25

Views: 4705

Answers (2)

Andriy Sorochan
Andriy Sorochan

Reputation: 11

You can use 'word wrap' or 'soft wraps' feature of your text editor. In the PyCharm if you search by soft you will see:

enter image description here

Upvotes: -1

juliomalegria
juliomalegria

Reputation: 24911

If you really want to keep those nasty long names, what I would do is:

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

Upvotes: 12

Related Questions