问题描述
我正在使用带有Whoosh后端的Django-Haystack。当我进行查询时,我没有任何结果。通过在Django shell中键入以下内容,我尝试了Haystack文档中建议的调试步骤,并且可以看到我想要的所有文本都已被索引。
I am using Django-Haystack with Whoosh backend. When I do a query I get no results. I tried the debugging steps suggested in the Haystack docs by typing the following into a Django shell, and I can see that all the text I want has been indexed.
from haystack.query import SearchQuerySet
sqs = SearchQuerySet().all()
sqs.count()
sqs[0].text
我的search.html页面具有以下部分(直接从文档中复制):
My search.html page has the following section (copied straight from the documentation):
{% for result in page.object_list %}
<p>
<a href="{{ result.object.url }}">{{ result.object }}</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}
我还能尝试什么?
推荐答案
好吧,我不知道发生了什么,但是在示例中, page.object_list
可行,在我的真实项目中,我需要删除 page
前缀。
Well, I have no idea what's happening, but whereas in the examples page.object_list
works, in my real project I needed to remove the page
prefix. Painful to figure out.
现在可行:
{% for result in object_list %}
<p>
<a href="{{ result.object.url }}">{{ result.object }}</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}
这篇关于Django-Haystack在搜索表单中未返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!