<p>似乎代码片段在devserver上不起作用。请参阅文档:<a href="https://developers.google.com/appengine/docs/python/search/devserver" rel="nofollow noreferrer">https://developers.google.com/appengine/docs/python/search/devserver</a></p>
<blockquote>
<h1>Using the Python Development Server</h1>
<p>The Python development server runs on your local machine and emulates most of the Search API's capabilities. However, a few features are not currently available on the server. For the moment, you should not attempt to use the following features when you run on the development server:</p>
<h2>Functions in expressions</h2>
<p>These functions are not available:</p>
<ul>
<li>snippet()</li>
<li>geopoint()</li>
<li>distance()</li>
<li>pow()</li>
</ul>
</blockquote>
<p>正如<a href="https://stackoverflow.com/users/1954661">advoretsky</a>所说,<code>returned_expressions</code>必须是iterable。从文件中:</p>
<blockquote>
<p><strong>returned_expressions</strong></p>
<p>An iterable of FieldExpression to evaluate and return in search results.</p>
</blockquote>
<p>此外,请确保导入正确的<code>Query</code>和{<cd3>},这两个都可以在<code>google.appengine.ext.ndb</code>中找到。我更喜欢导入它们,这样它们就有了前缀,这样更易于阅读;-)</p>
<pre><code>from google.appengine.ext import ndb
from google.appengine.api import search
# Notice the nice distinction
ndb.Query
search.Query
</code></pre>