ImportError when using Haystack 2.0.0 with Django 1.5 and Gunicorn WSGI

I use django-haystack 2.0.0 to index my site, and it works fine until I upgraded to Django 1.5 and started using the WSGI interface. If I just use the django_gunicorn command, it works fine, but the Django documentation "strongly recommends". I use the gunicorn command.

When I launch my site using the gunicorn , Haystack gives the following error when loading any page:

ImportError: cannot import name signals

I have no problem importing signals from Django or Python shells. I use virtualenv and install all packages locally inside this environment. My wsgi.py file looks the same as the default in the django admin, except that I add the local path to the python path as such:

 path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2]) if path not in sys.path: sys.path.append(path)` 

Any help you could provide would be greatly appreciated, thanks!

+4
source share
1 answer

I do not use gunicorn, but I had the same problem when I used the HAYSTACK_SIGNAL_PROCESSOR parameter to point to the custom class that I wrote. This class imported one of my models, which eventually spread the import chain to import my settings module, thereby causing circular import.

When using a parameter, such as HAYSTACK_SIGNAL_PROCESSOR, that points to a class, make sure the class is left at the same level and does not directly or indirectly import the Django settings file.

+7
source

Source: https://habr.com/ru/post/1485650/


All Articles