fromdjango.utils.safestring import mark_safefromdjango.http.request import QueryDictclassPagination:"""page: 当前的页码数
all_count: 总的数据量
per_num : 每页显示的数据量
max_show: 最多显示的页码数"""def __init__(self, page, all_count,params=None, per_num=10, max_show=11):try:
self.page= int(page)if self.page <= 0:
self.page= 1except Exception:
self.page= 1# 查询条件
self.params = params
if not self.params:
self.params = QueryDict(mutable=True)
# 总的数据量
all_count=all_count
# 每页显示的数据量10# 总的页码数
total_num, more=divmod(all_count, per_num)ifmore:
total_num+= 1# 最大显示的页码数
half_show= max_show //2
if total_num <=max_show:
page_start= 1page_end=total_numelse:if self.page - half_show <= 0:
# 页码的起始值