运行 python manage.py build_solr_schema 出现TypeError

1 篇文章 0 订阅
1 篇文章 0 订阅

原文出处https://github.com/django-haystack/django-haystack/issues/1519

问题:

运行 python manage.py build_solr_schema 出现如下错误:
TypeError : context must be a dict rather than Context
这里写图片描述

解决方法:

1.检查haystack是否为最新版(推荐版本(我用的版本)):
Operating system version: Ubuntu 16.04.2 LTS (GNU/Linux 4.8.0-54-generic x86_64)
Search engine version: solr 4.10.4
Python version: 3.5
Django version: 1.11.4
Haystack version: 2.6.1

2.打开 site-packages\haystack\management\commands\build_solr_schema.py文件
打开build_solr_schema.py文件

    def build_context(self, using):
        backend = connections[using].get_backend()

        if not isinstance(backend, SolrSearchBackend):
            raise ImproperlyConfigured("'%s' isn't configured as a SolrEngine)." % backend.connection_alias)

        content_field_name, fields = backend.build_schema(
            connections[using].get_unified_index().all_searchfields()
        )
        return Context({
            'content_field_name': content_field_name,
            'fields': fields,
            'default_operator': constants.DEFAULT_OPERATOR,
            'ID': constants.ID,
            'DJANGO_CT': constants.DJANGO_CT,
            'DJANGO_ID': constants.DJANGO_ID,
        })

修改为:

 def build_context(self, using):
        backend = connections[using].get_backend()

        if not isinstance(backend, SolrSearchBackend):
            raise ImproperlyConfigured("'%s' isn't configured as a SolrEngine)." % backend.connection_alias)

        content_field_name, fields = backend.build_schema(
            connections[using].get_unified_index().all_searchfields()
        )
        Context = {
            'content_field_name': content_field_name,
            'fields': fields,
            'default_operator': constants.DEFAULT_OPERATOR,
            'ID': constants.ID,
            'DJANGO_CT': constants.DJANGO_CT,
            'DJANGO_ID': constants.DJANGO_ID,
        }
        return Context

3.重新运行 python manage.py build_solr_schema
显示为:
这里写图片描述

运行成功,输出schema.xml的代码内容

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值