我读了这篇文章http://eshlox.net/en/2012/09/13/sphinxsearch-and-django-ubuntu/
鉴于我收到代码错误:total = query_results['total']
错误:“NoneType”对象没有属性“ getitem ”
def search(request):
if request.GET:
form = SearchForm(request.GET)
query = request.GET.get('q', '')
s = SphinxClient()
s.SetServer('localhost', 9312)
s.SetLimits(0, 16777215)
if s.Status():
query_results = s.Query(query)
total = query_results['total']
pages_id = [page['id'] for page in query_results['matches']]
if pages_id:
results = Page.objects.filter(id__in=pages_id)
else:
results = None
if results:
paginator = Paginator(results, 25)
page = request.GET.get('page')
try:
results = paginator.page(page)
except PageNotAnInteger:
results = paginator.page(1)
except EmptyPage:
results = paginator.page(paginator.num_pages)
return render(request, 'wiki/search.html',
{'results': results,'total': total,
'query': query, 'form': form})
else:
logger = logging.getLogger('helper')
logger.error('Sphinxsearch Error! %s' % s.GetLastError())
messages.add_message(request, messages.ERROR, 'Search server is '
'not responding. Administrator '
'has been informed.')
form = SearchForm()
return render(request, 'wiki/search.html', {'form': form})
else:
form = SearchForm()
return render(request, 'wiki/search.html', {'form': form})
Traceback 切换到复制和粘贴视图
/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in
获取响应
response = wrapped_callback(request, *callback_args, **callback_kwargs) ... ▶ Local vars /home/max/askmoiseev/ask/views.py in search total = query_results['total'] ... ▶ Local vars
请告诉我可能是什么错误?