【发布时间】:2015-06-02 17:36:49
【问题描述】:
我的问题是我似乎无法将字典翻译成表格,这是错误:
Could not parse ["appid"] from 'game[''appid"]
HTML 代码:
<table>
<tr>
<th>Game ID</th>
<th>Game Name</th>
<th>Hours Played</th>
</tr>
{% for game in games %}
{# each game object is a dictionary with "appid", "name " and "playtime_forever" keys #}
<tr>
<td>{{ game["appid"] }}</td>
<td>{{game["name"]}}</td>
<td>{{ game["playtime_forever"] }}</td>
</tr>
</table>
views.py 代码:
~~~~ There's stuff here but it shouldn't be important. ~~~~
return render(request,'hackathon/SteamAPI.html', game)
当我运行服务器时,它显示:
游戏:
[{u'appid': 4000,
u'has_community_visible_stats': True,
u'img_icon_url': u'd9101cbeddcc4ff06c7fa1936c3f381b0bbf2e92',
u'img_logo_url': u'dca12980667e32ab072d79f5dbe91884056a03a2',
u'name': u"Garry's Mod",
u'playtime_forever': 0},
【问题讨论】:
-
这个问题已经被问过很多次了。 stackoverflow.com/questions/1275735/…