我刚刚更新到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
答案 0 :(得分:2)
是的,这是因为在Haystack的2.0版本中,haystack.site被删除了。 Haystack API在这个新版本中经历了一些重大变化,但仍然没有稳定版本。使用1.2.7仍然是Django和基于文档的搜索引擎的特色版本。
您可以阅读entire documentation here有关如何将1.x版本迁移到2.x
的信息希望它有所帮助! :)