2016-04-22 43 views
0

我正在實施帶有whoosh搜索引擎的乾草堆。當我運行'rebuild_index'時,我的終端出現以下錯誤。(haystack + woosh)'rebuild_index'在錯誤的位置尋找模板?

File "/home/dilts/installingDJANGO/ENV/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/submit_app/incident_text.txt 

這個錯誤在我的瀏覽器中。

reduce() of empty sequence with no initial value 
incidents = SearchQuerySet().autocomplete(content_auto=request.POST.get(title, '')) 
return clone.filter(six.moves.reduce(operator.__and__, query_bits)) 

我的通用文件結構如下所示...

project 
|--------submit_app 
|--------search_app (uses a submit_app model called Incident) 
|--------templates (where I put search/indexes/search_app/incident_text.txt) 

從我在線閱讀,我相信我的結構是正確的,但是從錯誤中,我沒有那麼確定了。我覺得可能會與共享模型混淆,但我不知道。

settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
WHOOSH_INDEX = os.path.join(BASE_DIR,'whoosh/') 

HAYSTACK_CONNECTIONS = { 
    'default':{ 
     'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', 
     'PATH': WHOOSH_INDEX, 
    }, 
} 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, 'templates')], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
      ], 
     }, 
    }, 
] 

views.py

from django.shortcuts import render 
from .forms import IncidentsSearchForm 
from django.contrib.auth.decorators import login_required 
from haystack.query import SearchQuerySet 

@login_required(login_url='/login/') 
def incidents(request): 

    if request.method == 'POST': # If the form has been submitted... 
     form = IncidentsSearchForm(request.POST) # A form bound to the POST data 
     if form.is_valid(): # All validation rules pass 
      title = form.cleaned_data['title'] 

      ## this piece isn't working at I had hoped 
      incidents = SearchQuerySet().autocomplete(content_auto=request.POST.get(title, '')) 

    else: 
     form = IncidentsSearchForm() # An unbound form 
     title = '' 
     incidents = '' 

    return render(request, 'search.html', 
     { 
     'form': form, 
     'title': title, 
     'incidents' : incidents, 
     } 
    ) 

回答

0
當你有( 'haystack.urls')

,將默認搜索查找/ search.html。你有一個search.html文件嗎?

/templates/search/search.html 

views.py

return render(request, 'search/search.html', 
     { 
     'form': form, 
     'title': title, 
     'incidents' : incidents, 
     }