zoukankan      html  css  js  c++  java
  • Django 简易版分页器

    from django.shortcuts import render,HttpResponse
    from app01 import models

    #
    # def user_list(request):
    # for i in range(500):
    # dic = {'name':'name_%d' % i, 'age':i}
    # models.User.objects.create(**dic)
    # return HttpResponse('OK')
    #
    #


    def user_list(request):
    current_page = request.GET.get('page',1)
    print(current_page)
    current_page = int(current_page)
    start1 = (current_page-1)*10
    end1 = current_page*10
    all_item = models.User.objects.all().count()
    all_page ,div = divmod(all_item, 10)
    if div > 0:
    all_page +=1
    page_str = ''
    if all_page <=11:
    start = 1
    end = all_page
    else:
    if current_page <=6:
    start = 1
    end = 11 + 1
    else:
    start = current_page - 5
    end = current_page + 6
    if current_page + 6 > all_page:
    start = all_page - 10
    end = all_page + 1
    for i in range(start,end):
    if i == current_page:

    temp = '<a style="color:red; font-size:26px;padding: 5px" href="/user_list/?page=%d">%d</a>'% (i,i)
    else:
    temp = '<a href="/user_list/?page=%d">%d</a>' % (i, i)

    page_str += temp


    user_list = models.User.objects.all()[start1:end1]
    return render(request,'user_list.html',{'user_list':user_list, 'page_str':page_str})
    人生苦短,我用python
  • 相关阅读:
    地址栏传值 JS取值方法
    定位导航 制作
    验证码
    图片水印
    AJAX 三级联动
    javascript 和Jquery 互转
    Jquery 事件 DOM操作
    Jquery 基础
    软件工程中的形式化方法读后感
    软件工程理论、方法与实践 需求工程读后感
  • 原文地址:https://www.cnblogs.com/niucunguo/p/13903394.html
Copyright © 2011-2022 走看看