【发布时间】:2017-02-25 13:38:50
【问题描述】:
我的字典看起来有些像这样。
allCurrencies = {
'AUD': ['Australian Dollar', 'au'],
'GBP': ['British Pound', 'gb'],
'CAD': ['Canadian Dollar', 'ca'],
'INR': ['Indian Rupee', 'in'],
'JPY': ['Japanese Yen', 'jp'],
'RUB': ['Russian Ruble', 'ru'],
'SGD': ['Singapore Dollar', 'sg'],
'CHF': ['Swiss Franc', 'ch'],
'USD': ['US Dollar', 'us']
}
我的数组包含这个:
commonCurrencies = ['USD', 'EUR', 'GBP', 'JPY']
我的主要目标是迭代 commonCurrencies 并将其用作字典 allCurrencies 的键。
我的 django 模板目前如下所示:
<tr>
{% for sym in commonCurrencies %}
<td>{{allCurrencies.sym.0}}<td>
{% endfor %}
</tr>
但它似乎不起作用。我究竟做错了什么。谢谢
【问题讨论】:
-
你见过this answer
标签: python django list dictionary django-templates