是否有可能检测到来自Django请求的浏览器刷新? [英] Is it possible to detect a browser refresh from a Django request?

查看:50
本文介绍了是否有可能检测到来自Django请求的浏览器刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在Django请求中检测到用户刷新浏览器?

Is it possible to detect a browser refresh by a user within a Django request?

推荐答案

就我个人而言,我相信仅通过查看请求对象就无法知道刷新页面的方法.客户可以轻松打开该页面的第二个版本.您还必须保留有关所有请求的一些状态数据,以便比较诸如时间戳之类的东西,但这仅是对实际发生情况的假设...

By itself, I believe there would not be a way to know a page was refreshed just by looking at a request object. A client could easily have opened a second version of the page. You would also have to preserve some state data about all of the request in order to compare something like timestamps, but that would all just be assumptions about what really happened...

您可能可以做的是结合使用django检查请求和一些JavaScript魔术.这样做的原因是,客户端是唯一真正知道页面刷新是否正在发生并且必须记录此操作的某些状态的客户端.快速搜索在此处找到了这个小教程:检测页面刷新::在客户端使用JavaScript .它捕获页面卸载并设置cookie值,然后在下次重新加载时进行检查.您也许可以使用该方法的一部分来设置cookie,然后检查

What you can probably do is a combination of checking the request in django, and some javascript magic. The reason for this, is the client side is the only one that really knows if a page refresh is happening and must record some state for this action. A quick search turned up this little tutorial here: Detecting Page Refreshes :: Using JavaScript on Client-Side. It catches the page unload and sets cookie values, which is then checks on the next reload. You may be able to use part of that approach to set the cookie, and then check the request.cookies in your django view to see if that request recorded a page reload event.

*注意:我链接的那个javascript页面有些旧,但是该信息仍然有用.这是一个类似的SO问题

*Note: That javascript page I linked is a bit old, but the information is still relevant. Here is a similar SO question

这篇关于是否有可能检测到来自Django请求的浏览器刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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