Reputation: 230
[Not really sure if the topic makes sense, but didn't found a more meaningful one.]
I've created a template which looks like:
{% for x in jobs %}
<table>
<tr>
<td></td>
<td>{{ x.Ecordov.oovorder }}</td>
</tr>
<tr>
<td></td>
<td>{{ x.ooaname1.split('{}')[0] }}</td>
</tr>
<tr>
<td></td>
<td>{{ x.ooaname2.split('{}')[0] }}</td>
</tr>
<tr>
<td></td>
<td>{{ x.ooazusatz.split('{}')[0] }}</td>
</tr>
</table>
{% endfor %}
As you can see, I'm getting a specific position in multiple lists, which works quite well.
The problem I'm trying to solve: These lists have up to 16 positions, which I have to render. I could of course copy/paste the above <tr> </tr>
block 16 times into the template, and edit the line positions, but I'm quite sure that there is a better, more automated, way; however, I wasn't able to find this out on my own up until now.
Could anyone point me into the correct direction?
Thanks for any help and all the best!
Upvotes: 0
Views: 1192
Reputation: 9110
Try this:
{% for x in jobs %}
{% for i in range(0, 17) %}
<table>
<tr>
<td></td>
<td>{{ x.Ecordov.oovorder }}</td>
</tr>
<tr>
<td></td>
<td>{{ x.ooaname1.split('{}')[i] }}</td>
</tr>
<tr>
<td></td>
<td>{{ x.ooaname2.split('{}')[i] }}</td>
</tr>
<tr>
<td></td>
<td>{{ x.ooazusatz.split('{}')[i] }}</td>
</tr>
</table>
{% endfor %}
{% endfor %}
If you don't know how many elements does the list have you have to find it first and use it as the stop argument (the second argument of the range()
function).
Upvotes: 1