<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 分頁 ## 分頁 * django提供了一些類實現管理數據分頁,這些類位于django/core/paginator.py中 ## Paginator對象 * Paginator\(列表,int\):返回分頁對象,參數為列表數據,每面數據的條數 ### 屬性 * conut:對象總數 * num\_pages:頁面總數 * page\_range:頁碼列表,從1開始,例如\[1,2,3,4\] ### 方法 * page\(num\):下標以1開始,如果提供的頁碼不存在,拋出InvalidPage異常 ### 異常exception * InvalidPage:當向page\(\)傳入一個無效的頁碼時拋出 * PageNotAnInteger:當向page\(\)傳入一個不是整數的值時拋出 * EmptyPage:當向page\(\)提供一個有效值,但是那個頁面上沒有任何對象時拋出 ## Page對象 ### 創建對象 * Paginator對象的page\(\)方法返回Page對象,不需要手動構造 ### 屬性 * object\_list:當前頁上所有對象的列表 * number:當前頁的序號,從1開始 * paginator:當前page對象相關的Paginator對象 ### 方法 * has\_next\(\):如果有下一頁返回True * has\_previous\(\):如果有上一頁返回True * has\__other\_pages\(\):如果有上有一頁或下一頁返回True_ * next_\_page\_number\(\):返回上一頁的頁碼,如果上一頁不存在,拋出InvalidPage異常_ * len\(\):返回當前頁面對象的個數 * 迭代頁面對象:訪問當前頁面中的每個對象 ## 示例 #### 創建視圖studentpage ```text from .models import Students,Grades from django.core.paginator import Paginator def studentpage(request,pageid): if pageid == "": pageid = '1' # 所有學生列表 stuList = Students.objects.filter(isDelete=False) # 劃分為5個為一頁 pageNum = int(len(stuList)/5) # 第幾份數據 paginator = Paginator(stuList,pageNum) # 獲取第pageid的數據 page = paginator.page(pageid) print("pageid:",pageid) return render(request,'studentpage.html',{'students':page}) ``` ### 配置url ```text # url(r'^studentpage/(\d+)/$', views.studentpage), re_path(r'studentpage/(?P<pageid>\d+)/$', views.studentpage), ``` ### 定義模板studentpage.html ```text <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <ul> {% for stu in students %} <li> {{ stu.sname }} -- {{ stu.sgrade }} </li> {% endfor %} </ul> <ul style=""> {% for index in students.paginator.page_range %} {% if index == students.number %} <li> {{ index }} </li> {% else %} <li> <a href="/studentpage/{{index}}">{{index}}</a> </li> {% endif %} {% endfor %} </ul> </body> </html> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看