您当前的位置: 首页 > 

IT之一小佬

暂无认证

  • 0浏览

    0关注

    1192博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

数据统计之日活跃用户统计

IT之一小佬 发布时间:2021-07-27 21:11:56 ,浏览量:0

日活跃用户统计 接口分析

请求方式:GET /meiduo_admin/statistical/day_active/

    #  日活跃用户统计
    url(r'^statistical/day_active/$', statistical.UserActiveCountView.as_view()),

请求参数: 通过请求头传递jwt token数据。

返回数据: JSON

{
        "count": "活跃用户量",
        "date": "日期"
}
返回值类型是否必须说明countint是活跃用户量datedate是日期 后端实现
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAdminUser
from datetime import date

from users.models import User

class UserActiveCountView(APIView):
     # 指定管理员权限
    permission_classes = [IsAdminUser]

    def get(self,request):
        # 获取当前日期
        now_date=date.today()
        # 获取当日登录用户数量  last_login记录最后登录时间
        count=User.objects.filter(last_login__gte=now_date).count()
        return Response({
            "count":count,
            "date" : now_date
        })

postman测试:

关注
打赏
1665675218
查看更多评论
立即登录/注册

微信扫码登录

0.0374s