Disable browser #39;Back#39; button after logout?(注销后禁用浏览器“返回按钮?)
问题描述
我正在使用 python 和 django 我希望用户在注销后单击返回按钮时重定向到登录页面.如何做到这一点?代码在哪里写?
I am using python with django i want redirect users to login page when he clicks back button after logout. How to achieve this? where to write the code?
为了测试 django admin 是否处理这个..我登录到 django admin..注销然后点击返回按钮,我可以看到上一页.为什么 django admin 不处理这个.
To test whether django admin handles this..i logged into django admin..logged out and then hit back button and i am able to see the previous page. Why django admin does not handle this.
这是django admin中用于注销的ccode:
This is the ccode for logout in django admin:
def logout(request):
"""
Removes the authenticated user's ID from the request and flushes their
session data.
"""
request.session.flush()
if hasattr(request, 'user'):
from django.contrib.auth.models import AnonymousUser
request.user = AnonymousUser()
推荐答案
终于找到解决办法了:
from django.views.decorators.cache import cache_control
@cache_control(no_cache=True, must_revalidate=True)
def func()
#some code
return
这将强制浏览器向服务器发出请求.
This will force the browser to make request to server.
这篇关于注销后禁用浏览器“返回"按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:注销后禁用浏览器“返回"按钮?


基础教程推荐
- 如何添加到目前为止的天数? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01