I have an ordered list that I’m rendering as a 2-column html table in a Django template. In the table, the elements should be output so that the first (n+1)/2 elements are in the first column and the remainder are in the second column, as follows:
<table>
<tr>
<td>Elem 1</td>
<td>Elem 4</td>
</tr>
<tr>
<td>Elem 2</td>
<td>Elem 5</td>
</tr>
<tr>
<td>Elem 3</td>
<td></td>
</tr>
</table>
Assuming that my elements are in the context as {{ elems }}, how could I reasonably accomplish this in a Django template?
Check this recipe. You might have to modify it, but you will get the idea.
Using it, in your template you would just do: