1

我刚刚更新到 Haystack 版本 2,并且在尝试执行以前使用 1.7.2 的搜索时收到 ImportError。

cannot import name site

追溯:

Traceback:
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Users/nb/Desktop/nutmegstore/apps/haystack/views.py" in __call__
  45.         self.form = self.build_form()
File "/Users/nb/Desktop/nutmegstore/apps/haystack/views.py" in build_form
  72.         return self.form_class(data, **kwargs)
File "/Users/nb/Desktop/nutmegstore/apps/haystack/forms.py" in __init__
  90.         self.fields['models'] = forms.MultipleChoiceField(choices=model_choices(), required=False, label=_('Search In'), widget=forms.CheckboxSelectMultiple)
File "/Users/nb/Desktop/nutmegstore/apps/haystack/forms.py" in model_choices
  12.     choices = [("%s.%s" % (m._meta.app_label, m._meta.module_name), capfirst(smart_unicode(m._meta.verbose_name_plural))) for m in connections[using].get_unified_index().get_indexed_models()]
File "/Users/nb/Desktop/nutmegstore/apps/haystack/utils/loading.py" in get_indexed_models
  268.             self.build()
File "/Users/nb/Desktop/nutmegstore/apps/haystack/utils/loading.py" in build
  197.             indexes = self.collect_indexes()
File "/Users/nb/Desktop/nutmegstore/apps/haystack/utils/loading.py" in collect_indexes
  166.                 search_index_module = importlib.import_module("%s.search_indexes" % app)
File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/Users/nb/Desktop/nutmegstore/nutmegmodels/search_indexes.py" in <module>
  3. from haystack import site

Exception Type: ImportError at /search/
Exception Value: cannot import name site
4

1 回答 1

2

是的,这是因为在 Haystack 的 2.0 版本中删除了 haystack.site。Haystack API 在这个新版本中发生了一些重大变化,目前还没有稳定发布。使用 1.2.7 仍然是 Django 和基于文档的搜索引擎的特色版本。

您可以在此处阅读有关如何将 1.x 版本迁移到 2.x的整个文档

希望能帮助到你!:)

于 2013-03-28T20:37:09.757 回答