用烧瓶计数不重复的访客 [英] counting unique visitors with flask

查看:54
本文介绍了用烧瓶计数不重复的访客的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算唯一身份访问者的人数并将该人数存储在我的数据库中.我知道我可以通过

I would like to count the number of unique visitors and store that number in my database. I know that I can get the ip address with

request.remote_addr

所以我的默认计划是将该地址和时间戳存储在我的数据库中.对于任何新的访问者,我都会比较是否已添加该IP地址且其时间戳少于1天.这将使我每天有多少访客.

so my default plan would be to store this address with a timestamp in my database. For any new visitor I would than compare whether this ip address has already been added with a timestamp less than 1 day old. This would give me the number of visitors per day.

但是,我觉得这是一个问题,其他人可能已经想出了更好的解决方案?有什么建议可以做得更好吗?

However, I have the feeling this is a problem where others probably came up with better solutions already? Any suggestion how to do this better?

p.s.我只需要对不重复访问的次数进行一个粗略的估算,因此,IP地址不是一个很好的衡量标准,这与我无关……但是,如果您有更好的建议,我肯定会感兴趣

p.s. I just need a rough estimate for the number of unique visits, so the fact that ip addresses are not a good measure is not that concerning to me... but if you have better suggestions I am definitely interested

推荐答案

要获得更快,更可靠的解决方案,只需将该功能卸载到其他服务中,例如 Google Analytics(分析).它们为您的网站流量提供了非常详细/深入的视图,而您不必担心复杂的细节.

To get a faster more reliable solution, simply offload this functionality to another service like Google Analytics. They provide a very detailed/in-depth view of the traffic on your website without you having to worry about the intricate details.

无论如何,如果您对使用烧瓶一无所知,请查看此处是该应用程序的完整源代码.

Regardless, if you're dead set on using flask, take a look at this wonderful blog post explaining how to build an analytics app in Flask. Here is the complete source code of that app.

这篇关于用烧瓶计数不重复的访客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆