from django.http import HttpResponse
from django.http import JsonResponse
from django.core import serializers
from polls.models import *
import datetime
import time
from django.db.models import Sum
from django.core.paginator import Paginator
from django.forms.models import model_to_dict
def GetRetainData(request):
"""
留存数据
"""
beginTime = request.GET.get('begintime') if request.GET.get('begintime') else "2010-07-8"
endTime = request.GET.get('endtime') if request.GET.get('endtime') else "2019-07-8"
#转换成时间戳
start = int(time.mktime(time.strptime(beginTime, "%Y-%m-%d")))
end = int(time.mktime(time.strptime(endTime, "%Y-%m-%d")))
obj = TbUserStatistics.objects.filter(time__range=(start,end)).order_by('time').all() #时间段查询
#分页
paginator = Paginator(obj, 2) #每页条数
page = request.GET.get('page') #页码
data = paginator.get_page(page)
#print(obj.query) #打印sql
#print(data,data.object_list)
# data = model_to_dict(obj.first()) #将model转成字典格式
data_list = []
dnu_sum = 0
for i in data.object_list:
data_list.append(model_to_dict(i))
dnu_sum += i.dnu #统计总数
des = {}
d
Python分页案例
最新推荐文章于 2023-06-19 11:04:24 发布
本文通过Python的views.py代码展示了如何实现分页,并提供了相应的前端HTML代码,配合截图展示了实际效果。虽然示例简单,但易于理解。
摘要由CSDN通过智能技术生成