Python implements custom paging function

零到壹度
Release: 2018-04-19 15:32:35
Original
2414 people have browsed it

The example in this article describes the implementation of custom paging function in python. Share it with everyone for your reference, the details are as follows:

# 实现自定义分页
import math
def custom_paginator(current_page, num_page, max_page=10):  
  middle = math.ceil(max_page / 2)    
  # 一种特殊情况    
  # 总页数,小于最大页数    
  if num_page < max_page:    
      start = 1        
      end = num_page    
  else:    
      # 一般情况        
      # 当前页在头部的时候        
  if current_page <= middle:      
      start = 1            
      end = max_page        
  # 当前页在中间时        
  elif (current_page > middle) & (current_page < num_page - middle + 1):      
      start = current_page - middle            
      end = current_page + middle - 1        
  else:            
  # 当前页在尾部      
      start = num_page - max_page + 1            
      end = num_page    
  return start, end
Copy after login

Related recommendations:

js custom paging

Implementing custom paging function in ASP.NET

ThinkPHP5 custom paging tutorial

Implementation code of custom paging function

The above is the detailed content of Python implements custom paging function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!