I'm currently working in a django project in which I do some data analysis using pandas library and want to display the data (which is converted into a dictionary) as a HTML table.
dictionary that I want to display:
my_dict = {
'id': [1, 2, 3, 4, 5],
'product_name': [product1, product2, product3, product4, product5],
'value': [200, 400, 600, 800, 1000],
'available_qty': [1, 2, 3, 2, 4]
}
I want to display the above dictionary like this table in django template.
| id | product_name | value | available_qty |
|---|---|---|---|
| 1 | product1 | 200 | 1 |
| 2 | product2 | 400 | 2 |
| 3 | product3 | 600 | 3 |
| 4 | product4 | 800 | 2 |
| 5 | product5 | 1000 | 4 |
I have tried the below code.
<table>
<thead><h2><b>my dictionary</b></h2></thead>
{% for key, values in my_dict.items %}
<th><b>{{ key }}</b></th>
{% for value in values %}
<tr>
{{value}}
</tr>
{% endfor %}
{% endfor %}
</table>
I get the results as,
(There is some space between each row displayed in the table)
