Login

Django Twitter Bootstrap 3 pagination

Author:
Ragnar_Lodbrok
Posted:
February 2, 2014
Language:
Python
Version:
1.6
Score:
4 (after 4 ratings)

Twitter Bootstrap 3 default pagination with all pages indexes and controls for Django 1.6 ListView template.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{% if is_paginated %}
        <ul class="pagination pagination-centered">
            {% if page_obj.has_previous %}
                <li><a href="?page=1"><<</a></li>
                <li><a href="?page={{ page_obj.previous_page_number }}"><</a></li>
            {% endif %}

            {% for i in paginator.page_range %}
                <li {% if page_obj.number == i %} class="active" {% endif %}><a href="?page={{i}}">{{i}}</a></li>
            {% endfor %}

            {% if page_obj.has_next %}
                <li><a href="?page={{ page_obj.next_page_number }}">></a></li>
                <li><a href="?page={{ page_obj.paginator.num_pages }}">>></a></li>
            {% endif %}
        </ul>
    {% endif %}

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

danilchenko (on November 30, 2014):

You shouldn't use ">" and "<" symbols in HTML. Replace it with "»" and "«" respectively.

#

danilchenko (on November 30, 2014):

& raquo; AND & laquo;

#

iewgnaw (on December 25, 2014):

if page_range is large, it would be awful

#

tgdn (on April 10, 2015):

Maybe check something I built to help out https://github.com/tgdn/django-bootstrap-pagination

#

Please login first before commenting.