Skip to content

Instantly share code, notes, and snippets.

@nnewman
Created January 10, 2016 20:09
Show Gist options
  • Select an option

  • Save nnewman/e96b6389a8ff8161dca3 to your computer and use it in GitHub Desktop.

Select an option

Save nnewman/e96b6389a8ff8161dca3 to your computer and use it in GitHub Desktop.
Template code for adding pagination to a Django template with bootstrap3 styling
{% if is_paginated %}
<nav>
<ul class="pagination">
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}">{% if not page_obj.has_previous %}<span aria-hidden="true">{% endif %}&laquo; Previous</span><span class="sr-only">Previous</span></a></li>
{% endif %}
{% for page in paginator.page_range %}
<li {% if page_obj.number == forloop.counter %}class="active"{% endif %}><a href="?page={{forloop.counter}}">{{forloop.counter}}</a></li>
{% endfor %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}">{% if not page_obj.has_next %}<span aria-hidden="true">{% endif %}Next &raquo;</span><span class="sr-only">Next</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