注销后禁用浏览器“返回"按钮?

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.

这篇关于注销后禁用浏览器“返回"按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:注销后禁用浏览器“返回"按钮?