【发布时间】:2020-11-18 09:02:59
【问题描述】:
搜索结果没有出现在第二页我应该改变什么来解决我的问题?我正在使用弹性搜索作为搜索引擎 index.html
<ul>
{% for i in paginator.page_range %}
{% if i <= page_number|add:5 and i >= page_number|add:-5 %}
<li class=" {% if i == page_number %} active {% endif %} " >
<a href="?page={{forloop.counter}}">{{forloop.counter}}</a>
</li>
{% endif %}
{% endfor %}
</ul>
这是我的观点.py
def index(request):
q = request.GET.get('q')
if q:
articles = PostDocument.search().query("match", title=q, )
paginator = Paginator(articles, 5)
page_number = request.GET.get('page', 1)
page_obj = paginator.get_page(page_number)
return render(request, 'index.html', {
'articles': page_obj.object_list,
'paginator': paginator,
'page_number': int(page_number),
})
else:
articles = ''
return render(request, 'index.html', {'articles': articles})
【问题讨论】:
标签: django templates elasticsearch view pagination