Created
September 9, 2019 10:02
-
-
Save mmospanenko/2a160c27fc8969bb4967e65a7da56bcc to your computer and use it in GitHub Desktop.
Django bootstrap 4 pagination template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if page.has_other_pages %} | |
<nav aria-label="Page navigation"> | |
<ul class="pagination pg-dark justify-content-center"> | |
{% if page.has_previous %} | |
<li class="page-item"><a class="page-link" href="?page={{ page.previous_page_number }}">«</a></li> | |
{% else %} | |
<li class="page-item disabled"><a class="page-link" href="#"><span>«</span></a></li> | |
{% endif %} | |
{% for i in paginator.page_range %} | |
{% if page.number > 3 and forloop.first %} | |
<li class="page-item"><a class="page-link" href="?page=1">1</a></li> | |
<li class="page-item disabled"><a class="page-link" href="#"><span>...</span></a></li> | |
{% endif %} | |
{% if page.number == i %} | |
<li class="page-item active"><a class="page-link" href="#">{{ i }} <span class="sr-only">(current)</span></a> | |
</li> | |
{% elif i > page.number|add:'-3' and i < page.number|add:'3' %} | |
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li> | |
{% endif %} | |
{% if page.paginator.num_pages > page.number|add:'3' and forloop.last %} | |
<li class="page-item disabled"><a class="page-link" href="#"><span>...</span></a></li> | |
<li class="page-item"><a class="page-link" | |
href="?page={{ page.paginator.num_pages }}">{{ page.paginator.num_pages }}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% if page.has_next %} | |
<li class="page-item"><a class="page-link" href="?page={{ page.next_page_number }}">»</a></li> | |
{% else %} | |
<li class="page-item disabled"><a class="page-link" href="#"><span>»</span></a></li> | |
{% endif %} | |
</ul> | |
</nav> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment