How to display following dictionary in template: inventory = {'1': "{'Name': 'Server1', 'IP': '192.168.1.1', 'Version': 'Win'}", '2': "{'Name': 'Server2', 'IP': '192.168.1.2', 'Version': 'Linux'}", '3': "{'Name': 'Server3', 'IP': '192.168.1.3', 'Version': 'Win'}"}
I want to display in following format in HTML but I cannot figure it out:
Hostname IP Version
Server1 192.168.1.1 Win
Server2 192.168.1.2 Linux
Server3 192.168.1.3 Win
I tried following method:
Views.py: return render(request, 'inventory.html', inventory)
Template:
{% for i in inventory.values %}
{% for Name, IP, Version in i.items %}
<tr>
<td>{{ Name }}</td>
<td>{{ IP }}</td>
<td>{{ Version }}</td>
</tr>
{% endfor %}
{% endfor %}
Side Note: When posting code or templates here, surround the code (or template) between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep the text properly formatted.
(I’ve taken the liberty of fixing your original post for this.)