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

2022-01-25 00:00:00 python django django-admin javascript

我正在使用 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.

相关文章