Issue
Given a list of objects in a Django view function, such as
[['1.1.1.1', A], ['2.2.2.2', B]]
How can I iterate through them in an html template to make table rows
Column1 Column2
1.1.1.1 A
2.2.2.2 B
If you have a different way to do it, by creating the array/list in different way (no objects, but a list of elements for instance, please feel free to share).
Solution
In your views:
context['table_info'] = [['1.1.1.1', 'A'], ['2.2.2.2', 'B']]
Then in your template use a for loop:
<table>
<tr>
<th>Column1</th>
<th>Column2</th>
</tr>
{% for item in table_info %}
<tr>
<td>{{ item.0 }}</td>
<td>{{ item.1 }}</td>
</tr>
{% endfor %}
</table>
Answered By - ben432rew
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.