由于django提供了paginator模块,直接调用就行
如:from django.core.paginator import Paginator
但是django实现搜索后分页,只会显示第一页,其他页都无法正确显示。
后知道,django的请求分页是GET模式,而且需要在a标签里传递我们的搜索内容。
代码:
<nav aria-label="Page navigation">
<ul class="pagination">
<li >
{% if current_page.has_previous %}
<a href="/cpname_detail/?page={
{ current_page.previous_page_number }}**&cpname={
{name}}**" aria-label="Previous" >
<span aria-hidden="true" >«</span>
</a>
{% endif %}
</li>
{% for page_num in page_range %}
{% if page_num == current_num %}