def goodlist(request,typeid,pageid,sort): count=request.session.get('count') newgood=GoodsInfo.objects.all().order_by('-id')[:2] if sort=='1': sumGoodList=GoodsInfo.objects.filter(gtype_id=typeid).order_by('-id') elif sort=='2': sumGoodList=GoodsInfo.objects.filter(gtype_id=typeid).order_by('gprice') elif sort=='3': sumGoodList=GoodsInfo.objects.filter(gtype_id=typeid).order_by('-gclick') paginator=Paginator(sumGoodList,15) goodList=paginator.page_range(int(pageid)) pindexList=paginator.page_range goodtype=TypeInfo.objects.get(id=typeid) context={'title':'商品详情','list':1,'guest_cart':1,'goodtype':goodtype,'newgood':newgood,'goodList':goodList, 'typeid':typeid,'sort':sort,'pindexList':pindexList,'pageid':int(pageid),'count':count} return render(request,'df_goods/list.html',context)
def device_view(request): filter = request.GET.get('filter', "") if filter: p_device = device.objects.filter( Q(device_name__contains=filter) | Q(device_type__contains=filter) | Q(model__contains=filter) | Q(serial_no__contains=filter) | Q(ip__exact=filter)) else: p_device = device.objects.all() NUM_PER_PAGE = 10 paginater = Paginator(p_device, NUM_PER_PAGE) page = request.GET.get('page') try: contexts = paginater.page(page) except PageNotAnInteger: contexts = paginater.page(1) except EmptyPage: contexts = paginater.page_range(paginater.num_pages) return render_to_response('cmdb/device.html', { 'device': contexts, 'filter': filter }) pass
def idc_view(request): filter = request.GET.get('filter', "") if filter: p_idc = models.idc.objects.filter( Q(idc_name__contains=filter) | Q(address__contains=filter) | Q(idc_type__contains=filter)) else: p_idc = models.idc.objects.all() NUM_PER_PAGE = 10 paginater = Paginator(p_idc, NUM_PER_PAGE) page = request.GET.get('page') try: contexts = paginater.page(page) except PageNotAnInteger: contexts = paginater.page(1) except EmptyPage: contexts = paginater.page_range(paginater.num_pages) return render_to_response('cmdb/idc.html', { 'idc': contexts, 'filter': filter }) pass
def index(request): book_list = [] # 模拟数据 for i in range(999): temp = {'name': 'root' + str(i), 'age': i} book_list.append(temp) # Book.objects.bulk_create(book_list) #builk_create 是批量创建数据 # print(Paginator.count) #总数据量 # print(Paginator.num_pages) #分页数 # print(Paginator.page_range) #显示的是页数的标记 就是按钮的数目 # book_list = Book.objects.all() paginator = Paginator(book_list, 2) # 设置每一页显示几条 创建一个panginator对象 # try: # current_num = int(request.GET.get('page',1)) # # book_list = paginator.page(current_num) # print(paginator.count) #通过你创建的对象来调用pangnator的属性 这个是统计总数 # print(paginator.num_pages) #因为你上面设置了每一页显示两条 这个分页就会是总数除去每一页的显示的数量 # print(paginator.page_range) # book_list = paginator.page(1) #这个是对你的分页的数据进行取值 去除你的分过后的第一页 # # book_list , paginator.page是取你的分页后的某一页 # print(book_list) # book_list = Book.objects.all() # paginator = Paginator(book_list, 2) # 设置每一页显示几条 创建一个panginator对象 try: current_num = int(request.GET.get( 'page', 2)) # 当你在url内输入的?page = 页码数 显示你输入的页面数目 默认为第2页 book_list = paginator.page(current_num) except EmptyPage: book_list = paginator.page(4) # 当你输入的page是不存在的时候就会报错 if paginator.num_pages > 11: # 如果分页的数目大于11 if current_num - 5 < 1: # 你输入的值 pageRange = range(1, 11) # 按钮数 elif current_num + 5 > paginator.num_pages: # 按钮数加5大于分页数 pageRange = range(current_num - 5, current_num + 1) # 显示的按钮数 else: pageRange = range(current_num - 5, current_num + 6) # range求的是按钮数 如果你的按钮数小于分页数 那么就按照正常的分页数目来显示 else: pageRange = paginator.page_range() # 正常分配 return render(request, 'index2.html', locals())
def domain_view(request): filter = request.GET.get('filter', "") if filter: p_domain = dm.objects.filter(Q(dm_name__contains=filter)) else: p_domain = dm.objects.all() NUM_PER_PAGE = 10 paginater = Paginator(p_domain, NUM_PER_PAGE) page = request.GET.get('page') try: contexts = paginater.page(page) except PageNotAnInteger: contexts = paginater.page(1) except EmptyPage: contexts = paginater.page_range(paginater.num_pages) return render_to_response('cmdb/domain.html', { 'domain': contexts, 'filter': filter }) pass