Talukder Nobin
Talukder Nobin

Reputation: 31

NameError: name 'base' is not defined(haystack search)

I wanted to include full text search in my django application. I am using whoosh-haystack for this.When I include whoosh and haystack in my installed apps,and execute the command ./manage.py, I am getting an import error. Can anyone sort this out.

settings.py
INSTALLED_APPS = {
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'search',
   'whoosh',
   'haystack',
 }

when I make migration in my model the error which I got is:

Traceback (most recent call last):
     File "manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
     File "C:\Users\Samad Talukder\AppData\Local\Programs\Python  \Python36\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
     File "C:\Users\Samad Talukder\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 303, in execute
settings.INSTALLED_APPS
     File "C:\Users\Samad Talukder\AppData\Local\Programs\Python\Python36\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
self._setup(name)
     File "C:\Users\Samad Talukder\AppData\Local\Programs\Python\Python36\lib\site-packages\django\conf\__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
     File "C:\Users\Samad Talukder\AppData\Local\Programs\Python\Python36\lib\site-packages\django\conf\__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
     File "C:\Users\Samad Talukder\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
     File "<frozen importlib._bootstrap>", line 978, in _gcd_import
     File "<frozen importlib._bootstrap>", line 961, in _find_and_load
     File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
     File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
     File "<frozen importlib._bootstrap_external>", line 678, in exec_module
     File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
     File "C:\Users\Samad Talukder\Desktop\django-env\search\search\settings.py", line 80, in <module>
    'PATH': os.path.join(base(), 'whoosh_index')
    NameError: name 'base' is not defined

my haystack connection:

HAYSTACK_CONNECTIONS = {
'default': {
    'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
    'PATH': os.path.join(base(), 'whoosh_index')
  },
}

my models.py:

 from django.contrib.auth.models import User
 from django.db import models

 class Author(User):
      pass

 class Book(models.Model):
      title = models.CharField(max_length=300)
      author = models.ForeignKey(Author)
      isbn = models.CharField(max_length=300)
      resume = models.TextField()

      def __unicode__(self):
          return self.title

for more information I install haystack and whoosh in my django project by django pip install method like this:

pip install haystack
pip install whoosh

Upvotes: 1

Views: 3030

Answers (1)

bruno desthuilliers
bruno desthuilliers

Reputation: 77912

The traceback is quite clear:

File "C:\Users\Samad Talukder\Desktop\django-env\search\search\settings.py", line 80, in <module>
    'PATH': os.path.join(base(), 'whoosh_index')
    NameError: name 'base' is not defined

This means that line #80 of your settings.py file uses a name (base - obviously expected to be a function) that is not defined. Your settings file is missing either an import or a function definition. What base is supposed to do etc is beyond our knowledge (it's definitly not a builtin, and nothing standard in a django settings file) but you should now since it's your project.

Upvotes: 2

Related Questions