如何在Django中自定义引导分页?

时间:2018-09-23 05:27:39

标签: python django bootstrap-4

how to reduce the no displayed in the pagination in the image there are 12 page no displayed whereas I just want 3 page no to be displayed only

这是Django分页的默认代码:

{% load bootstrap4 %}
{% with bpurl=bootstrap_pagination_url|default:"" %}

    <ul class="{{ pagination_css_classes }}">

        <li class="prev page-item{% if current_page == 1 %} disabled{% endif %}">
            <a class="page-link" href="{% if current_page == 1 %}#{% else %}{% bootstrap_url_replace_param bpurl parameter_name 1 %}{% endif %}">
                &laquo;
            </a>
        </li>

        {% if pages_back %}
            <li class="page-item">
                <a class="page-link" href="{% bootstrap_url_replace_param bpurl parameter_name pages_back %}">&hellip;</a>
            </li>
        {% endif %}

        {% for p in pages_shown %}
            <li class="page-item{% if current_page == p %} active{% endif %}">
                <a class="page-link" href="{% if current_page == p %}#{% else %}{% bootstrap_url_replace_param bpurl parameter_name p %}{% endif %}">
                    {{ p  }}
                </a>
            </li>
        {% endfor %}

        {% if pages_forward %}
            <li class="page-item">
                <a class="page-link" href="{% bootstrap_url_replace_param bpurl parameter_name pages_forward %}">&hellip;</a>
            </li>
        {% endif %}

        <li class="last page-item{% if current_page == num_pages %} disabled{% endif %}">
            <a class="page-link" href="{% if current_page == num_pages %}#{% else %}{% bootstrap_url_replace_param bpurl parameter_name num_pages %}{% endif %}">
                &raquo;
            </a>
        </li>

    </ul>

{% endwith %}

因此,我应该在哪里更改代码以显示较少的页面数。上面的代码是从Django-bootstrap4分页的默认代码中检索的 就像以此模式显示:
enter image description here

0 个答案:

没有答案