NameError:name' base'未定义(草堆搜索)

时间:2017-10-24 06:01:12

标签: python django django-haystack whoosh

我想在我的django应用程序中包含全文搜索。我正在使用whoosh-haystack。当我在已安装的应用程序中包含whoosh和haystack,并执行命令./manage.py时,我收到导入错误。任何人都可以解决这个问题。

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

当我在我的模型中进行迁移时,我得到的错误是:

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

我的干草堆连接:

 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

my models.py:

pip install haystack
pip install whoosh

有关更多信息,请通过django pip install方法在我的django项目中安装haystack和whoosh:

<script type="text/javascript">
function openCity(evt, cityName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(cityName).style.display = "block";
    evt.currentTarget.className += " active";
}</script>

1 个答案:

答案 0 :(得分:2)

追溯非常清楚:

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

这意味着您的settings.py文件的第80行使用了未定义的名称(base - 显然是一个函数)。您的设置文件缺少导入或函数定义。 base应该做什么等等超出我们的知识(它绝对不是内置的,并且在django设置文件中没有标准)但现在应该是因为它&#39 ; s 您的项目。