Skip to content

Instantly share code, notes, and snippets.

@ErickMwazonga
Forked from vitorfs/example.html
Created December 6, 2017 20:53
Show Gist options
  • Save ErickMwazonga/3a404bf9a02a0cb55fe0409e308e4434 to your computer and use it in GitHub Desktop.
Save ErickMwazonga/3a404bf9a02a0cb55fe0409e308e4434 to your computer and use it in GitHub Desktop.
Django Bootstrap Pagination Widget
<table class="table table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for article in articles %}
<tr>
<td>{{ article.title }}</td>
<td>{{ article.author }}</td>
<td>{{ article.date }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include 'paginator.html' with page_obj=articles %}
<ul class="pagination">
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="disabled"><span>&laquo;</span></li>
{% endif %}
{% for i in page_obj.paginator.page_range %}
{% if page_obj.number == i %}
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li><a href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}">&raquo;</a></li>
{% else %}
<li class="disabled"><span>&raquo;</span></li>
{% endif %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment