Last active
April 17, 2016 16:03
-
-
Save ceolson01/271f6ff5db35a90ef31e3ad1aefd8e13 to your computer and use it in GitHub Desktop.
Django & Bootstrap Pagination for Large Number of Pages
This file contains hidden or 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 listings.has_previous or listings.has_next %} | |
<div class="text-center"> | |
<ul class="pagination pagination-sm"> | |
{% if listings.has_previous %} | |
<li><a href="?page=1">1</a></li> | |
<li><a href="?page={{ listings.previous_page_number }}">‹</a></li> | |
{% endif %} | |
{% for i in paginator.page_range %} | |
{% if i < listings.number and i >= listings.number|add:"-4" and i != listings.number and i != 1 %} | |
<li><a href="?page={{i}}">{{i}}</a></li> | |
{% elif i > listings.number and i <= listings.number|add:"4" and i != listings.number and i != listings.paginator.num_pages %} | |
<li><a href="?page={{i}}">{{i}}</a></li> | |
{% elif listings.number == i %} | |
<li class="active"><a href="?page={{i}}">{{i}}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% if listings.has_next %} | |
<li><a href="?page={{ listings.next_page_number }}">›</a></li> | |
<li><a href="?page={{ listings.paginator.num_pages }}">{{ listings.paginator.num_pages }}</a></li> | |
{% endif %} | |
</ul> | |
</div> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment