def __init__(self, current_page_num, all_count, request,per_page_num=2, pager_count=11):"""封装分页相关数据
:param current_page_num: 当前访问页的数字
:param all_count: 分页数据中的数据总条数
:param per_page_num: 每页显示的数据条数
:param pager_count: 最多显示的页码个数"""
'''进行判断,如果输入的是字符串捕获之后整回第一页'''
try:
current_page_num=int(current_page_num)exceptException as e:
current_page_num=1
"""如果输入的是别的字符或者<1,直接给他第一页数据"""
if current_page_num <1:
current_page_num=1
#进行数据的实例化
self.current_page_num =current_page_num
self.all_count=all_count
self.per_page_num=per_page_num#计算实际的总页码 商和余 (pmod是内置函数)
all_pager,tmp =pmod(all_count,per_page_num)iftmp:
all_count= all_count+1self.all_pager=all_pager
self.pager_count