官方文档

    <div class="row">
      <div class="col-md-12">
        <ul class="pagination">
          {% if posts.has_previous %}
          <li class="page-item">
            <a href="?page=1" class="page-link">&laquo; 首页</a>
          </li>
          <li class="page-item">
            <a href="?page={{ posts.previous_page_number }}" class="page-link">上一页</a>
          </li>
          {% else %}
          <li class="page-item disabled">
            <a class="page-link">&laquo; 首页</a>
          </li>
          <li class="page-item disabled">
            <a class="page-link">1</a>
          </li>
          {% endif %}


          {% if posts.has_previous %}
          <li class="page-item">
            <a href="?page={{posts.previous_page_number}}" class="page-link">{{posts.previous_page_number}}</a>
          </li>

          <li class="page-item">
            <a class="page-link active">{{posts.number}}</a>
          </li>
          {% endif%}
          <!-- Page {{ posts.number }} of {{ posts.paginator.num_pages }}. -->
          {% if posts.has_next %}
          <li class="page-item">
            <a href="?page={{ posts.next_page_number }}" class="page-link">{{posts.next_page_number}}</a>
          </li>
          {% endif %}

          {% if posts.has_next %}

          <li class="page-item">
            <a href="?page={{ posts.next_page_number }}" class="page-link">下一页</a>
          </li>
          <li class="page-item">
            <a href="?page={{ posts.paginator.num_pages }}" class="page-link">最后一页 &raquo;</a>
          </li>
          {% else %}
          <li class="page-item disabled">
            <a class="page-link">最后一页 &raquo;</a>
          </li>
          {% endif %}
          <li class="page-item disabled">
            <a class="page-link">第{{posts.number}}页,共{{ posts.paginator.num_pages }}页 </a>
          </li>
        </ul>
      </div>
    </div>

效果:




分类: djangopython开发

发表评论

电子邮件地址不会被公开。 必填项已用*标注