Haystack + Django CMS搜索错误“空序列的reduce()没有初始值”

时间:2018-10-16 17:57:41

标签: python django django-haystack django-cms

我对Django世界比较陌生。我们的客户希望向他们的网站添加搜索功能,因此,我将按照以下说明集成Haystack和Aldryn Search:

https://github.com/aldryn/aldryn-search

我也经历过这里:https://django-haystack.readthedocs.io/en/v2.6.0/tutorial.html

  

异常位置:搜索中的env / lib / python2.7 / site-packages / haystack / backends / simple_backend.py,第79行

以下是一些有用的信息摘要:

urls.py-

(r'^search/', include('haystack.urls')),

templates / search / search.html-

{% extends 'base.html' %}

{% block content %}
<div class="primary-content">
<div class="container constrained">
    <form method="get" class="paragraph" action=".">
        {{ form.as_table }}
        <div class="text-right">
            <button type="submit" class="button">
                Search
            </button>
        </div>

        {% if query %}
            <h3>Results</h3>

            {% for result in page.object_list %}
                <div class="post-preview paragraph">
                    <h3>
                        <a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
                    </h3>
                </div>
            {% empty %}
                <p>No results found.</p>
            {% endfor %}

            {% if page.has_previous or page.has_next %}
                <div>
                    {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
                    |
                    {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
                </div>
            {% endif %}
        {% else %}
            {# Show some example queries to run, maybe query syntax, something else? #}
        {% endif %}
    </form>
</div>
</div>
{% endblock %}

settings.py-

HAYSTACK_CONNECTIONS = {
'default': {
    'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
},
}
HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter', ]
ALDRYN_SEARCH_REGISTER_APPHOOK = True
ALDRYN_SEARCH_PAGINATION = 20
ALDRYN_SEARCH_CMS_PAGE = True

此外,“干草堆”和“ aldryn_search”都位于INSTALLED_APPS中。

当我运行update_index --remove时,它似乎在大多数情况下都起作用:

Indexing 5 locations
Indexing 2 People
Indexing 16 articles

根据文档看来,我已正确完成了所有操作。但是我一定不能。我们的网站上只有一种语言,因此确实使文档难以理解,因为我不确定是否还有多余的东西才需要多语言。

堆栈跟踪:

['/build/healthdirect',
 '/build/env/lib/python27.zip',
 '/build/env/lib/python2.7',
 '/build/env/lib/python2.7/plat-darwin',
 '/build/env/lib/python2.7/plat-mac',
 '/build/env/lib/python2.7/plat-mac/lib-scriptpackages',
 '/build/env/lib/python2.7/lib-tk',
 '/build/env/lib/python2.7/lib-old',
 '/build/env/lib/python2.7/lib-dynload',

'/ System / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7',          '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',      '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',      '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',      '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',      '/build/env/lib/python2.7/site-packages']

0 个答案:

没有答案