运行 python manage.py build_solr_schema 出现TypeError

来源:互联网 发布:监控摄像头客户端软件 编辑:程序博客网 时间:2024/06/05 03:02

原文出处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 0
原创粉丝点击