python實現分頁外掛程式

2022-02-16 20:33:32 字數 2205 閱讀 8240

class

pages:

def__init__(self, current_page, data_count, per_page_count=10, pager_num=7):#

pager_num 這是頁碼

self.current_page =current_page

self.data_count =data_count

self.per_page_count =per_page_count

self.pager_num =pager_num

pass

@property

defstart(self):

return (self.current_page-1) *self.per_page_count

@property

defend(self):

return self.current_page *self.per_page_count

@property

defall_count(self):

v, s =divmod(self.data_count, self.per_page_count)

if s >0:

v += 1

return

v

defpage_str(self, base_url):

pg =

if self.all_count start_index = 1ent_index =self.all_count

else

:

if self.current_page < (self.pager_num + 1) / 2: #

最前面的數,當小於6時會出現的一種情況

start_index = 1ent_index =self.pager_num

elif self.current_page + 5 > self.all_count: #

最後面的數,當加上5大於總頁數時會出現的一種情況

start_index = self.all_count - self.pager_num + 1ent_index =self.all_count

else

: start_index = self.current_page - ((self.pager_num - 1) / 2)

ent_index = self.current_page + ((self.pager_num - 1) / 2)

pre_page = "

" %\

(base_url, self.current_page - 1 if self.current_page > 1 else 1)

for a in range(int(start_index), int(ent_index)+1):

if a ==self.current_page:

temp = "

%s" %(base_url, a, a)

else

: temp = "

%s" %(base_url, a, a)

next_page = "

" %\

(base_url, self.current_page + 1 if self.current_page < self.all_count else

self.all_count)

jump = """

跳轉""" %base_url

page_str = pre_page+"".join(pg)+next_page+jump

return page_str

使用例子:

def

show_vedio(request):

current_page = request.get.get("

p", 1)

current_page =int(current_page)

page_obj =pages(current_page, len(list))

lists =list[page_obj.start:page_obj.end]

return render(request, "

blogs/internet/show_video.html

", )

前端:

}

}

python 分頁外掛程式

class mypageplugin object def init self,totalitem,currentpage,url a none,perpageitem 3,showapage 9 param totalitem 總的條目數 param perpageitem 每頁顯示的條目 par...

Mybatis 10 實現分頁 分頁外掛程式

也就是說,在查詢結果的最後控制返回的起始位置 記錄數量 引數1 返回的開始位置 引數2 要返回的記錄數 但是,如果說是只寫了乙個引數,直接表示引數2處理 limit start index size 實際開發不會只寫乙個引數,使用者預設開啟一定是從第一條開始的 即 0 顯示的記錄數 引數的資料型別選...

PageHelper外掛程式實現分頁功能

一 新增依賴 com.github.pagehelper groupid pagehelper artifactid 5.1.1 version dependency 二 配置 配置屬性 offsetaspagenum true rowboundswithcount true pagesizezer...