我对以下行为感到困惑:
使用 Freebase-Python,我向 Freebase API 发送一个请求,该请求是对 JSON 响应的查询。我得到响应,例如:
"status": "200 OK",
"code": "\/api\/status\/ok",
"result": {
"\/common\/topic\/weblink": [
{
"url": "http:\/\/www.boardgamegeek.com\/boardgame\/13\/Settlers of Catan",
"description": "BoardGameGeek"
}
],
"id": "\/en\/settlers_of_catan"
}
在我用来发出请求的同一个 RequestHandler 类中,我可以执行以下操作,
print result.id
>>> /en/settlers_of_catan
print result["/common/topic/weblink"][0].url
>>> http://www.boardgamegeek.com/boardgame/13/Settlers of Catan
但是,当我将结果对象传递给 HTML 模板时,就会出现奇怪的行为。
我可以,
{{ result.id }}
这将在浏览器中呈现“/en/settlers_of_catan”。但如果我尝试,
{{ 结果["/common/topic/weblink"][0].url }}
我收到一个错误:
raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]
TemplateSyntaxError: Could not parse the remainder: ["/common/topic/weblink"][0].url
我也可以只显示结果:
{{ result }}
这导致浏览器:
{u'/common/topic/weblink': [{u'url': u'http://www.boardgamegeek.com/boardgame/13/Settlers of Catan', u'description': u'BoardGameGeek'}], u'id': u'/en/settlers_of_catan'}
我的问题是,为什么我不能像从 RequestHandler 一样访问 HTML 模板中的结果?