加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Haystack / Whoosh索引生成错误

发布时间:2020-12-20 12:16:04 所属栏目:Python 来源:网络整理
导读:我正试图用后嘶嘶声设置干草堆.当我尝试生成索引[或任何索引命令]时,我收到: TypeError: Item in ``from list'' not a string 如果我完全删除我的search_indexes.py我得到相同的错误[所以我猜它根本找不到该文件] 什么可能导致这个错误?它设置为自动发现,
我正试图用后嘶嘶声设置干草堆.当我尝试生成索引[或任何索引命令]时,我收到:

TypeError: Item in ``from list'' not a string

如果我完全删除我的search_indexes.py我得到相同的错误[所以我猜它根本找不到该文件]

什么可能导致这个错误?它设置为自动发现,我确定我的应用程序已安装,因为我正在使用它.

完全追溯:

Traceback (most recent call last):
  File "./manage.py",line 17,in <module>
    execute_manager(settings)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py",line 362,in execute_manager
    utility.execute()
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py",line 303,in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py",line 257,in fetch_command
    klass = load_command_class(app_name,subcommand)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py",line 67,in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name,name))
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/utils/importlib.py",line 35,in import_module
    __import__(name)
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py",line 124,in <module>
    handle_registrations()
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py",line 121,in handle_registrations
    search_sites_conf = __import__(settings.HAYSTACK_SITECONF)
  File "/Users/ghostrocket/Development/Redux/website/../website/search_sites.py",line 2,in <module>
    haystack.autodiscover()
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py",line 83,in autodiscover
    app_path = __import__(app,{},[app.split('.')[-1]]).__path__
TypeError: Item in ``from list'' not a string

这是我的search_indexes.py

from haystack import indexes
from haystack import site
from myproject.models import *

site.register(myobject)

解决方法

看起来你遇到了两个问题.

第一个是生成TypeError的那个.它发生在Haystack搜索您在INSTALLED_APPS中列出的每个应用程序中搜索search_indexes.py时(因为您正在自动注册).我不确定问题究竟是什么,但我首先要从列表中搜索你的项目并仔细检查你的代码.我以前没有遇到过这个例外,但是如果你在编写的代码中发生这种情况,你应该在你的问题中发布任何相关的部分

我相信你在使用或不使用search_indexes.py文件时得到相同错误的原因是因为它永远不会到达尝试执行该文件中的代码的程度.

也就是说,该文件中应该发生更多(这是第二个问题).您必须创建一个索引类(继承自haystack.indexes.SearchIndex)并将其注册到模型中.有关说明和示例,请参阅this section of the documentation.

我也会在django-haystack Google Group中提出这个问题,因为作者和干草堆的其他用户会在那里看到它,而且它们往往非常有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读