Skip to content

Instantly share code, notes, and snippets.

@zaemiel
Created July 20, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaemiel/0e7053ef5b135684be9a481b102ef390 to your computer and use it in GitHub Desktop.
Save zaemiel/0e7053ef5b135684be9a481b102ef390 to your computer and use it in GitHub Desktop.
Django pagination with bootstrap snippet
{% for n in posts.paginator.page_range %}
{% if posts.number == n %}
<li class="page-item active">
<span class="page-link">{{ n }}<span class="sr-only">(current)</span></span>
</li>
{% elif n > posts.number|add:'-2' and n < posts.number|add:'2' %}
<li class="page-item"><a class="page-link" href="?page={{ n }}">{{ n }}</a></li>
{% endif %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment