html_helper 分頁

來源:互聯網
上載者:User

標籤:turn   port   select   url   hang   [1]   cte   imp   ref   

 1 # -*- coding: utf-8 -*- 2  3 from django.utils.safestring import mark_safe 4 ‘‘‘ 5 Created on 2017年5月4日 6  7 change on 07May2017 8 ‘‘‘ 9 def model(page,per_item,M):10     try:11         page = int(page)12     except:13         page = 114     start = (page-1)*per_item15     end = page*per_item16     count = M.objects.all().count()17     result = M.objects.all()[start:end]18     print result19     temp = divmod(count, per_item)20     if temp[1] == 0 :21         all_page_count = temp[0]22     else:23         all_page_count = temp[0]+124     return all_page_count,result,count25 26 27 def pager(page,all_page_count,url):28     try:29         page = int(page)30     except:31         page = 132     #判斷如果頁面是1,則上一頁無,正常上一頁為當前少133     if page <= 1:34         page_html = "<a href=‘#‘>上一頁</a>"35     else:36         page_html = "<a href=‘%s/%d‘>上一頁</a>"%(url,page-1)37     #首頁就是第1頁38     page_html += "<a href=‘%s/%d‘>首頁</a>"%(url,1) 39     40     #頁面顯示11個頁碼,如果當前頁面少於5,則啟始頁為1,正常啟始頁為當前減541     if page< 11:42         page_start = 143         page_end = all_page_count+144     else:45         page_start = page-546         if all_page_count-6>=page:47             page_end = page+648         else:49             page_end = all_page_count50     51     for i in range(page_start,page_end):52         if page == i:53             a_html ="<a class=‘selected‘ href=‘%s/%d‘>%d</a>"%(url,i,i)54         else:55             a_html ="<a href=‘%s/%d‘>%d</a>"%(url,i,i)56         page_html += a_html57     58     page_html += "<a href=‘%s/%d‘>尾頁</a>"%(url,all_page_count)59     #60     if page <= all_page_count-1:61         page_html += "<a href=‘%s/%d‘>下一頁</a>"%(url,page+1)62     else: 63         page_html += "<a href=‘#‘>下一頁</a>"64     page =  mark_safe(page_html)65     return page

 

html_helper 分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.