注销后禁用浏览器"后退"按钮?

Viv*_*k S 4 javascript python django django-admin

我正在使用django的python我想要在注销后点击后退按钮时重定向用户登录页面.怎么做到这一点?在哪里写代码?

要测试django管理员是否处理此..我登录到django admin..log out,然后点击按钮,我能够看到上一页.为什么django管理员不处理这个问题.

这是django admin注销的ccode:

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()
Run Code Online (Sandbox Code Playgroud)

Viv*_*k S 13

终于找到了解决方案:

from django.views.decorators.cache import cache_control

@cache_control(no_cache=True, must_revalidate=True)
def func()
  #some code
  return
Run Code Online (Sandbox Code Playgroud)

这将强制浏览器向服务器发出请求.


Pol*_*her 9

您可能会发现需要在chrome中使用@cache_control(no_cache = True,must_revalidate = True,no_store = True)来完全停止任何后退按钮查看.

关键是chrome的no_store,我在这里找到了1