过去一天登录的用户数

时间:2021-07-12 15:21:56

I am building a python script that connects to a site's mysql database through the MySQLdb library. The site is based on django. I want to get the number of users that logged on the site in the past 24 hours, maybe using the django sessions table. How can I do this using only python and mysql?

我正在构建一个python脚本,通过MySQLdb库连接到站点的mysql数据库。该网站基于django。我想获得过去24小时内登录网站的用户数量,可能使用django会话表。我怎么能只用python和mysql做到这一点?

Thanks

1 个解决方案

#1


1  

from datetime import datetime, timedelta
from django.contrib.auth import User

yesterday = datetime.now() - timedelta(days=1)
users = User.objects.filter(last_login = yesterday)

Haven't tried this, but I think this should work

没有试过这个,但我认为这应该有效

#1


1  

from datetime import datetime, timedelta
from django.contrib.auth import User

yesterday = datetime.now() - timedelta(days=1)
users = User.objects.filter(last_login = yesterday)

Haven't tried this, but I think this should work

没有试过这个,但我认为这应该有效