Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

proper pagination django template

{% if is_paginated %}
    {% load proper_paginate %}
    {% load url_replace %}
    <ul class="pagination">
        {% if page_obj.number == 1 %}
            <li class="disabled"><span>⇤</span></li>
        {% else %}
            <li><a class="page-link" href="?{% url_replace request 'page' 1 %}">⇤</a></li>
        {% endif %}
        {% if page_obj.has_previous %}
            <li><a class="page-link" href="?{% url_replace request 'page' page_obj.previous_page_number %}">«</a></li>
        {% else %}
            <li class="disabled"><span>«</span></li>
        {% endif %}
        {% for i in paginator|proper_paginate:page_obj.number %}
            {% if page_obj.number == i %}
                <li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
            {% else %}
                <li><a class="page-link" href="?{% url_replace request 'page' i %}">{{ i }}</a></li>
            {% endif %}
        {% endfor %}
        {% if page_obj.has_next %}
            <li><a class="page-link" href="?{% url_replace request 'page' page_obj.next_page_number %}">»</a></li>
        {% else %}
            <li class="disabled"><span>»</span></li>
        {% endif %}
        {% if page_obj.number == paginator.num_pages %}
            <li class="disabled"><span>⇥</span></li>
        {% else %}
            <li><a class="page-link" href="?{% url_replace request 'page' paginator.num_pages %}">⇥</a></li>
        {% endif %}
    </ul>
{% endif %}
Source by gist.githubusercontent.com #
 
PREVIOUS NEXT
Tagged: #proper #pagination #django #template
ADD COMMENT
Topic
Name
5+7 =