我正在尝试实施干草堆和嗖的一声,当我进入
时 ./manage.py rebuild_index
我收到了这个巨大的错误
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
All documents removed.
Indexing 10 posts
ERROR:root:Error updating posts using default
Traceback (most recent call last):
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 188, in handle_label
self.update_backend(label, using)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 233, in update_backend
do_update(backend, index, qs, start, end, total, verbosity=self.verbosity, commit=self.commit)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 96, in do_update
backend.update(index, current_qs, commit=commit)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/backends/whoosh_backend.py", line 196, in update
doc = index.full_prepare(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/indexes.py", line 212, in full_prepare
self.prepared_data = self.prepare(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/indexes.py", line 203, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/fields.py", line 159, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/fields.py", line 79, in prepare
return self.prepare_template(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/fields.py", line 136, in prepare_template
t = loader.select_template(template_names)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/template/loader.py", line 74, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: search/indexes/posts/post_text.txt
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/rebuild_index.py", line 26, in handle
call_command('update_index', **options)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/core/management/__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 183, in handle
return super(Command, self).handle(*items, **options)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/core/management/base.py", line 548, in handle
label_output = self.handle_label(label, **options)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 188, in handle_label
self.update_backend(label, using)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 233, in update_backend
do_update(backend, index, qs, start, end, total, verbosity=self.verbosity, commit=self.commit)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 96, in do_update
backend.update(index, current_qs, commit=commit)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/backends/whoosh_backend.py", line 196, in update
doc = index.full_prepare(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/indexes.py", line 212, in full_prepare
self.prepared_data = self.prepare(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/indexes.py", line 203, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/fields.py", line 159, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/fields.py", line 79, in prepare
return self.prepare_template(obj)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/haystack/fields.py", line 136, in prepare_template
t = loader.select_template(template_names)
File "/Users/ray/Desktop/mypy/trydjango/lib/python3.5/site-packages/django/template/loader.py", line 74, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: search/indexes/posts/post_text.txt
也是我的settings.py
WHOOSH_INDEX = os.path.join(BASE_DIR, 'whoosh/')
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': WHOOSH_INDEX,
},
}
我不确定到底发生了什么。欢迎任何帮助。我一直试图修补它,但我还没有发现它是什么。我也没有在我的网站包中看到干草堆,就像它在上面的路径中所示
编辑:我在索引中添加了一个post目录,然后将post_text.txt放在其中。然后错误就消失了,但现在没有任何东西被归还,但它就像一个无形的列表正在推动我的CSS。这是怎么回事?
在终端我收到的消息如
Model could not be found for SearchResult '<SearchResult: posts.post (pk='20')>'.
Model could not be found for SearchResult '<SearchResult: posts.post (pk='20')>'.
[02/Feb/2016 15:34:11] "POST /posts/search/ HTTP/1.1" 200 32
答案 0 :(得分:1)
这只是因为use_template=True
search_indexes.py
将其use_template=False
否则,您必须指定模板。
您的查询结果是一组SearchResult
个对象,因此您必须获取模型对象。
类似这样的事情
sqs = SearchQuerySet().models(Model).load_all().auto_query(query)
orm_objects = orm_objects.filter(pk__in=sqs.values_list('pk', flat=True))
return orm_objects