Google App Engine:输出'值'来自Jinja2模板上的SearchResult对象。

时间:2014-05-17 18:19:22

标签: google-app-engine python-2.7 jinja2 google-search-api

我想返回SearchDocument对象的字段value。例如,我使用:

生成了一个SearchResult对象
class SearchResult(Handler):
    def get(self):
    index = search.Index("INDEX_NAME")
    results = index.search("Brian")
    self.render('search-result.html', results = results)

结果对象看起来像这样:

search.SearchResults(results=[
    search.ScoredDocument(
        doc_id=u'6122080743456768', 
        fields=[search.TextField(name=u'full_name', value=u"Brian Jones"), 
        language=u'en', 
        rank=106509239L), 
    search.ScoredDocument(
        doc_id=u'4714705859903488', 
        fields=[search.TextField(name=u'full_name', value=u"Brian Lara"), 
        language=u'en', 
        rank=106427057L)], 
    number_found=2L)

search-result.html 中,如何返回字段的value

...
<body>
{{ field_values }} #return the field values "Brian Lara" and "Brian Jones"
<body>
...

1 个答案:

答案 0 :(得分:0)

从这里开始:

{% for result in results %}
  {{ result.fields[0].value }}
{% endfor %}

(您的字段中有[&#39;不匹配。修复此问题,然后检查语法)