I have a data structure data as below which is passed in to the template. I want to iterate through that to get the values to be displayed in an HTML table like below
data = {
'section1_header': [
{
'r1_name': ['u1', 'u2', 'u3',]},
{
'r2_name': ['v1', 'v2', 'v3',]},
],
'section2_header': [
{
'R1_name': ['U1', 'U2', 'U3']},
{
'R2_name': ['V1', 'V2', 'V3']}
],}
display format:
section1_header
r1_name | u1 | u2 |u3
r2_name | v1 | v2 |v3
section2_header
R1_name | U1 | U2 |U3
R2_name | V1 | V2 |V3
I have applied the nested loops to access the values
{% for section,row_items in data.items() %}
<tr>
<td> {{section}} </td>
</tr>
{% for row_values in row_items %}
<tr>
{% for rowname,value_list in row_values.items() %}
<td>{{rowname}}</td
{% for value in value_list %}
<td>{{value}}</td>
{% endfor %}
{%endfor%}
</tr>
{% endfor %}
{% endfor %}
Upon rendering it is not printing the values other than the section. Any fix for this? If possible, without using templatetags.
The looping logic is fine, so I think the error is in the template that your rendering. Adapting from this answer, try the template below:
Running this code produced the below output. Of course, change the styling as you need it: