ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
If you get this error when you try to import haystack in Python shell, then you can use manage.py to set the undefined environment variable. Go to the project’s directory and run the command
python manage.py shell
Now, you should be able to import haystack without any error.