ich habe folgendes Dictionary:
Code: Alles auswählen
dictionary={'ort1': {'id': 43, 'test1': 'info test1 ', 'prod': 'info prod1', 'test2': 'info test2'}, 'ort2': {'id': 67, 'test1': 'info test1', 'prod': 'info prod', 'test2': 'info test2'},'ort3': {'id': 95, 'test1': 'info test1', 'prod': 'info prod', 'test2': 'info test2'},...}
Nun dachte ich mir, dass ich mittels einer if Bedingung und dem key festlege, in welcher spalte der Tabelle die richtige Info aus dem Dictionary ausgeben wird. Das klapp jedoch nicht so richtig. Ich hätte gern ein Tipp, wie ich dieses Problem lösen könnte
Dazu mal mein nicht funktionierender Versuch. Die Ausgabe in den Spalten erfolgt nach Dictionary Reihenfolge der keys und nicht nach der gewünschten in der Spalte.
Code: Alles auswählen
<table style="width:100%" id="table">
<thead>
<tr>
<th>Standort</th>
<th>Test1</th>
<th>Test2</th>
<th>PROD</th>
<th>Id</th>
</tr>
</thead>
<tbody>
{% for standort,infos in versions_data.items() -%}
<tr>
<td>{{ standort}}</td>
{% for key, info in infos.items() %}
{{ key }}
{% if key == "test1" %}<td>{{ info }} </td>{% endif %} {% if key == "test2" %}<td>{{ info }} </td> {% endif %}{% if key == "prod" %}<td>{{ info }} </td> {% endif %}{% if key == "id" %}<td>{{ info }} </td>{% endif %}
{% endfor %}
{% endfor %}
</tr>
</tbody>
</table>
</div>
</body>
</html>
VG niesel