django - 搜索后分页的第二页在 django 中不起作用
问题描述
搜索结果没有出现在第二页我应该改变什么来解决我的问题?我使用 elasticsearch 作为搜索引擎 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>
这是我的views.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})
解决方案
推荐阅读
- arrays - 如何为 Google 表格中的每一行重复查询单独的数据集?
- node.js - 使用 useState 反应钩子更新对象数组
- c# - 从 .NET Core 3.1 连接到 LDAP - 指定了无效的 dn 语法:NTLM (0x4E 0x54 0x4C 0x4D) 无效
- c# - 如何在 Windows 窗体应用程序中一次运行两个任务?
- java - 为什么 -from Java- JSON 返回此错误?显然是在 JSON 反序列化中,但我找不到它发生的确切位置
- javascript - 获取多维类数组对象中的项目
- node.js - 在 express 中管道(代理)图像流会产生一个空框
- python - 使用 xarray 和 CORDEX 数据绘制随时间变化的低压中心
- ios - Flutter:应用程序的 Info.plist 不包含 CFBundleVersion
- c++ - c++20 std::integral_constant?