1

我正在使用 Google App Engine Search API(在 Python 中),我希望能够在我的 jinja2 模板中打印特定的 search_document 字段。我在模板中使用此符号来尝试打印搜索文档的“评论”字段:

{{ scored_document.comment }}

我想要这个输出:

test

但相反,我得到了这个输出:

[search.TextField(name=u'comment', value=u'test')]

获取“comment”的正确语法是什么?

API 文档似乎表明您只能通过成员(列表对象)获取此值,.fields但此表示法似乎也不起作用:

{{ scored_document.fields.comment }}

我只是在github上扩展 Google 提供的 Search API 示例:

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" type="text/css" href="/static/css/main.css"/>
    <title>Search Demonstration App</title>
  </head>
  <body style="margin:20px;">

    <form action="/sign" method="post">
      <div>Search Demo</div>
      <div><textarea name="search" rows="1" cols="60"></textarea></div>
      <div><input type="submit" value="Search"/></div>
      <div><textarea name="content" rows="3" cols="60"></textarea></div>
      <div><input type="submit" value="Comment"/></div>
    </form>

    {{number_returned}} of {{results.number_found}} comments found <p>
    {% for scored_document in results %}

      <!-- Just want **value** of comment here: -->
      {{ scored_document.comment }}

      <p>
    {% endfor %}

    <a href="{{ url }}">{{ url_linktext }}</a>

  </body>
</html>
4

1 回答 1

1

您想要该字段的“值”属性:

{{ scored_document.comment.value }}
于 2013-05-14T17:21:47.890 回答