Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django template coding style line break for a long line of code

I have very long code in one line, like this

{% for student_id, name, gender, family_description, grade, class, date in report_info %}

Can I break that into two lines using slash or other symbol?

like image 323
Amber Chen Avatar asked Aug 29 '13 22:08

Amber Chen


Video Answer


1 Answers

Whenever I find myself trying to coerce Django's templating system to short-cut long lines of code like this, it's almost always a red-flag for me to rethink my data structure.

Perhaps you can consider changing report_info so that each item in report_info is actually a dict, or a class.

report_info = [
    {"student_id": id, "name": name, "gender": gender, ...},
    ...
]

And then in your template, the iteration is simple, and not long:

{% for report_item in report_info %}
    {{ report_item.student_id }}
    {{ report_item.name }}
    ...
{% endfor %}
like image 81
Quentin Donnellan Avatar answered Sep 24 '22 23:09

Quentin Donnellan