运行 python manage.py build_solr_schema 出现TypeError
2017-09-04 08:45
645 查看
原文出处https://github.com/django-haystack/django-haystack/issues/1519
TypeError : context must be a dict rather than Context
![](https://oscdn.geek-share.com/Uploads/Images/Content/201709/bc1f780b7a477a147bc8f35610fba731)
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文件
修改为:
3.重新运行 python manage.py build_solr_schema
显示为:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201709/e6288601134d66be90cbf6f1ec1b4d22)
运行成功,输出schema.xml的代码内容
问题:
运行 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的代码内容
相关文章推荐
- 运行 python manage.py build_solr_schema 出现TypeError
- 运行python .\manage.py migrate出现'on_delete'相关报错
- 运行python manage.py syncdb时出现“cannot connect to MySQL server on 'localhost'”的解决方法
- 之前在pycharm中已经装好pillow,但在命令行运行python manage.py runserver 0.0.0.0:8000 出现not install pillow
- 关于运行python .\manage.py runserver出现UnicodeDecodeError报错
- 运行python程序时出现错误“SyntaxError: Non-ASCII character '\xe8' in file variable.py on line 1, but no encod”
- 执行python manage.py runserver 0.0.0.0:8000,出现以下问题
- 玩django时运行python manage.py runserver时遇到问题
- 在运行envirtual环境创建项目,python manage.py migrate同步数据库问题
- python manage.py runserver启动服务器时出现10013错误
- 在python中运行selective-search.py出现no module named numpy错误
- Openwrt下安装Python3.5运行出现异常:Fatal Python error: Py_Initialize: Unable to get the locale encoding
- django 运行python manage.py sqlall books 时报错 app has migration
- window运行gradle build -- --stacktrace出现找不到文件framework-4.3.0.BUILD-SNAPSHOT-schema.zip异常
- 出现这个 python: can't open file 'manage.py': [Errno 2] No such file or directory
- 使用sae-python-dev本地运行web.py项目出现module object has no attribute InteractiveInterpreter
- django使用python manage.py syncdb注意事项
- python manage.py dbshell
- TypeError:a bytes-like object is requeired ,not 'int'(使用python3编写出现的错误)
- python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level