I have a list of phones dicts, and I want to break it into 2 columns. I have some solution but it looks dirty. What's the right and simplest way to do it?
My solution is here:
myphones dict is here:
myphones = [
{'number':'13888888881',
'fee' = '1'},
{'number':'13888888882',
'fee' = '1'},
{'number':'13888888883',
'fee' = '1'},
{'number':'13888888884',
'fee' = '1'},
{'number':'13888888885',
'fee' = '1'},
{'number':'13888888886',
'fee' = '1'},
]
in the templates: I write:
<pre>
{% for phone in myphones %}
<tr>
<td>
{{phone.number}}
</td>
<td>
{{phone.fee}}
</td>
<td>
{{phone.number}}
</td>
<td>
{{phone.fee}}
</td>
</tr>
{% endfor %}
</pre>
It like this:
Try:
{% for i in range(0, ((myphones|length)/2)|int, 2) %}
<tr>
<td>
{{myphone[i].number}}
</td>
<td>
{{myphone[i].fee}}
</td>
{% if (i+1) <= (myphone|length-1)%}
<td>
{{myphone[i+1].number}}
</td>
<td>
{{myphone[i+1].fee}}
</td>
{% endif %}
</tr>
{% endfor %}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments