Home >Backend Development >Python Tutorial >Python implements custom paging function

Python implements custom paging function

零到壹度
零到壹度Original
2018-04-19 15:32:352491browse

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

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!

Statement:
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