Django Rest 框架分析
我已经在互联网上搜索了几个小时,但找不到答案,所以这是我最后的手段。
你们知道捕获用户发送了多少数据(假设对特定端点的获取请求)的最佳方法是什么吗?我还希望能够通过用户是在移动应用程序还是在网站(同一端点)上发送请求来区分。
我想过制作一个类似的模型:
class Visit(models.Model)
product = models.ForeignKey('Product')
user = models.ForeignKey('User')
on_mobile = models.BooleanField(default='False')
on_website = models.BooleanField(default='False')
times_visit = models.IntegerField(default=0)
然后拍摄
if Visit.objects.get(user=self.request.user, product=self.kwargs['pk']).exists():
times_visit += 1
Visit.objects.create(user=self.request.user, product=self.kwargs['pk'])
你知道如何“检查”用户是否通过移动应用程序或网站发送它吗? 或者也许还有其他更好的方法? 我将感谢任何形式的帮助。
I've been searching the internet for hours and can't find answer so this is my last resort.
Do you guys have any idea what's the best way to capture how much a user has sent let's say get request for a specific endpoint? I also want it to be distinguishable by whether the user sent a request on a mobile app or on a website (the same endpoint).
I thought about making a model something like:
class Visit(models.Model)
product = models.ForeignKey('Product')
user = models.ForeignKey('User')
on_mobile = models.BooleanField(default='False')
on_website = models.BooleanField(default='False')
times_visit = models.IntegerField(default=0)
and shooting
if Visit.objects.get(user=self.request.user, product=self.kwargs['pk']).exists():
times_visit += 1
Visit.objects.create(user=self.request.user, product=self.kwargs['pk'])
Do you have any idea how "check" whether user sent it through mobile app or website?
Or maybe there is some other better way?
I would be thankful for any kind of help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该解析用户代理。有一些库可以做到这一点。
我使用这个库。
https://pypi.org/project/user-agents/
You should parse user agent. There is some library for that.
I use this library.
https://pypi.org/project/user-agents/