当前位置:网站首页>paging
paging
2022-04-22 07:13:00 【Daodao 777999】
class Page:
def __init__(self, curPage, all, perPage, showPage):
''' :param curPage: The current page :param all: # Number of data :param perPage: # Number of data per page :param showPage: # Show how many page numbers '''
a, b = divmod(all, perPage) # Seeking remainder , The first is business , The second is the remainder
if b != 0:
a = a + 1
self.allPage = a
self.showPage = showPage
self.perPage = perPage
try:
self.curPage = int(curPage)
if self.curPage > self.allPage:
self.curPage = self.allPage
except Exception:
self.curPage = 1
def start(self):
return (self.curPage - 1) * self.perPage
def end(self):
return self.curPage * self.perPage
def pager(self):
half = int(self.showPage / 2)
# Less than showPage, All show
if self.allPage < self.showPage:
begin = 1
end = self.allPage + 1
else: # Greater than showPage
begin = self.curPage - half
end = self.curPage + half + 1
# Consider extreme cases
if self.curPage - half <= 0 or self.curPage + half > self.allPage:
if self.curPage - half <= 0:
begin = 1
end = self.showPage + 1
if self.curPage + half > self.allPage:
begin = self.allPage - self.showPage
end = self.allPage + 1
pagelist = []
if self.curPage > 1:
# Contains some bootstrap Style content
pagelist.append(
'<li class="page-item"><a class="page-link" href="./?page=%s "> The previous page </a></li>' % (self.curPage - 1,))
else:
pagelist.append('<li class="page-item"><a class="page-link"> There is no previous page </a></li>')
for i in range(begin, end):
temp = '<li class="page-item"><a class="page-link" href="./?page=%s">%s</a></li>' % (i, i)
if i == self.curPage:
temp = '<li class="page-item active"><a class="page-link">%s</a></li>' % (i,)
pagelist.append(temp)
if self.curPage < self.allPage:
pagelist.append(
'<li class="page-item"><a class="page-link" href="./?page=%s"> The next page </a></li>' % (self.curPage + 1))
else:
pagelist.append('<li class="page-item"><a class="page-link"> There is no next page </a></li>')
return ''.join(pagelist)
def custom(req):
curPage = req.GET.get('page')
perPage = 8 # each page 8 individual
userlist = models.userInfo.objects.all() # filter(id__lt=30)
page = Page(curPage, len(userlist), perPage, 10)
return render(req, './App2/custom.html', {
'userlist': userlist[page.start():page.end()], 'page': page})
Add |Safe To avoid django Of xss Defense mechanisms

版权声明
本文为[Daodao 777999]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220608104042.html
边栏推荐
- Oracle JDK vs OpenJDK
- 从 Spec.到芯片_(数字IC、模拟IC、FPGA/CPLD设计的流程及EDA工具)
- 分布式任务调度与计算框架:PowerJob 快速开始(本地IDE版) 02
- From spec. to chip_ (Digital IC, analog IC, FPGA / CPLD design process and EDA tools)
- Nacos persistent switch configuration
- 如何成为IC验证工程师?
- Typical application cases of can optical fiber converter and can bus optical transceiver in fire Networking (buildings, factories, offshore wind power, pipe gallery, etc.)
- Solution of overdetermined equation
- leetcode打卡日记 day 01
- 旋转选择器 WheelPicker 的使用
猜你喜欢

集成电路模拟版图入门-版图基础学习笔记(二)

PowerJob 工作流

Can bus record diagnostic assistant

Nacos持久化切换配置

Nacos服务消费者注册和负载均衡

Mcs-5 interrupt technology (Theory)

CLion和动态链接库

Quantify the relationship between 911 calls and years from 2015 to 2017

Design of second-order RC low-pass filter for PWM wave to DC

Fields in uppercase accept the final initial but become lowercase
随机推荐
Start with stm32f4 floating point operation (FPU) function + use DSP Library
实验室安全考试
利用线程工厂设定线程池中线程名称
ParseException Unparseable date 时间转换异常
fastmock使用说明
C daily development notes -- solve the problem that one set references another set, resulting in changes together
Quantify PM2 in 5 cities 5 changes over time
Application of mcicecan in industrial computer
Remote program upgrade scheme of transparent cloud gateway in construction machinery under epidemic environment
Can transparent recording cloud gateway enables construction machinery
送给所有程序员的新年祝福&新年愿望
Nacos服务消费者注册和负载均衡
[review of Blue Bridge Cup] tree of life
数字IC设计自学入门难吗?如何快速入门呢?
Relationship between Nacos namespace grouping and dataid
Does microelectronics major make chips? What is the chip related to?
[Blue Bridge Cup] load balancing
老程序员常逛的网站(持续更新)
leetcode 打卡
VScode 看这一篇就够了