
{% load djacore_tags %}
{% if page_obj.paginator.num_pages > 1 %}
<nav aria-label="Page navigation" class="my-md-5 my-3">
    <ul class="pagination justify-content-center mb-0">
        {# 首页按钮（当距离首页超过3页时显示） #}
        {% if page_obj.number > 3 %}
        <li class="page-item">
            <a class="page-link" href="{% modify_url page=1 %}">
                <span aria-hidden="true">首页</span>
            </a>
        </li>
        {% endif %}

        {# 上一页按钮 #}
        {% if page_obj.has_previous %}
        <li class="page-item">
            <a class="page-link" href="{% modify_url page=page_obj.previous_page_number %}">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </li>
        {% endif %}

        {# 页码显示 #}
        {% for p in page_obj|visible_pages:3 %}
        <li class="page-item {% if p == page_obj.number %}active{% endif %}">
            <a class="page-link" href="{% modify_url page=p %}" 
               {% if p == page_obj.number %}aria-current="page"{% endif %}>
                {{ p }}
            </a>
        </li>
        {% endfor %}

        {# 下一页按钮 #}
        {% if page_obj.has_next %}
        <li class="page-item">
            <a class="page-link" href="{% modify_url page=page_obj.next_page_number %}">
                <span aria-hidden="true">&raquo;</span>
            </a>
        </li>
        {% endif %}

        {# 总页数显示 #}
        <li class="page-item ">
            <a class="page-link" href="{% modify_url page=page_obj.paginator.num_pages %}">
                共 {{ page_obj.paginator.num_pages }} 页
            </a>
        </li>
    </ul>
</nav>
{% endif %}
