python – Поиск в django: ‘NoneType’ object has no attribute ‘_default_manager’


Hello, I recently started learning django, I got to the search and here's an error like this: AttributeError at / blog / search / 'NoneType' object has no attribute '_default_manager' when entering a value in the search field that is not in the index, it returns an empty value if enter the value that is – will return this:


Request Method: GET
Request URL:

Django Version: 1.9.2
Python Version: 3.4.3
Installed Applications:
Installed Middleware:


File "/home/yurka/VENV/lib/python3.4/site-packages/haystack/" in post_process_results
  213.                     index = ui.get_index(model)

File "/home/yurka/VENV/lib/python3.4/site-packages/haystack/utils/" in get_index
  308.             raise NotHandled('The model %s is not registered' % model_klass)

During handling of the above exception (The model None is not registered), another exception occurred:

File "/home/yurka/VENV/lib/python3.4/site-packages/django/core/handlers/" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/home/yurka/VENV/lib/python3.4/site-packages/django/core/handlers/" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/yurka/VENV/lib/python3.4/site-packages/django/views/generic/" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/home/yurka/VENV/lib/python3.4/site-packages/django/views/generic/" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/home/yurka/VENV/lib/python3.4/site-packages/haystack/" in get
  123.             return self.form_valid(form)

File "/home/yurka/VENV/lib/python3.4/site-packages/haystack/" in form_valid
  80.             'object_list': self.queryset

File "/home/yurka/VENV/lib/python3.4/site-packages/django/views/generic/" in get_context_data
  134.             paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)

File "/home/yurka/VENV/lib/python3.4/site-packages/django/views/generic/" in paginate_queryset
  78.             page =

File "/home/yurka/VENV/lib/python3.4/site-packages/django/core/" in page
  55.         return self._get_page(self.object_list[bottom:top], number, self)

File "/home/yurka/VENV/lib/python3.4/site-packages/haystack/" in __getitem__
  272.                 self._fill_cache(start, bound)

File "/home/yurka/VENV/lib/python3.4/site-packages/haystack/" in _fill_cache
  191.         to_cache = self.post_process_results(results)

File "/home/yurka/VENV/lib/python3.4/site-packages/haystack/" in post_process_results
  219.                     loaded_objects[model] = model._default_manager.in_bulk(models_pks[model])

Exception Type: AttributeError at /blog/search/
Exception Value: 'NoneType' object has no attribute '_default_manager'

here is the search view:

class PostSearch(SearchView):
    template_name = 'blog/post/search.html'
    queryset = SearchQuerySet().models(Post).load_all()
    total_results = queryset.count()
    form_class = SearchForm

here is the template:

{% extends "blog/base.html" %}

{% block title %}Search{% endblock %}

{% block content %}
    {% if "q" in request.GET %}
        <h1>Posts containing "{{ q }}"</h1>
        <h3>Found {{ total_results }} result{{ total_results|pluralize }}</h3>
        {% for result in queryset %}
            {% with post=result.object %}
                <h4><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h4>
                {{ post.body|truncatewords:5 }}
            {% endwith %}
        {% empty %}
            <p>There are no results for your query.</p>
        {% endfor %}
        <p><a href="{% url "blog:haystack_search" %}">Search again</a></p>
    {% else %}
        <h1>Search for posts</h1>
        <form action="." method="get">
            {{ form.as_p }}
            <input type="submit" value="Search" class="button">
    {% endif %}
{% endblock %}

there is nothing unusual in the models. Here are the other modules installed:

Django == 1.9.2 django-haystack == 2.4.1 django-taggit == 0.18.0 elasticsearch == 2.3.0 Markdown == 2.6.5 pysolr == 3.4.0 pytz == 2015.7 requests == 2.9.1 urllib3 == 1.14 wheel == 0.29.0

in the search itself, it looks for both elastic and solr.


I found it in the haystack documentation: Haystack currently only supports ElasticSearch 1.x. ElasticSearch 2.x is not supported yet

Scroll to Top