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.
这篇关于注销后禁用浏览器“返回"按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:注销后禁用浏览器“返回"按钮?


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01