簡體   English   中英

用戶在django中注銷后如何拒絕訪問上一頁?

[英]How deny access to the previous page when a user have logged out in django?

我是django的新手,我在Ubuntu服務器上使用1.8版本,我成功完成了登錄和注銷過程,但是當我的用戶嘗試轉到上一頁時,他們可以將其視為匿名用戶。 我如何拒絕訪問?

我嘗試在views.py上使用if,但是不起作用:

def login(request):
    if not request.user.is_authenticated():
        return render(request,"base.html",{})
    return render(request,"general.html",{})

@login_required 
def general(request):
    return render(request,"general.html")

希望可以有人幫幫我。

編輯:我正在使用django的默認URL登錄和注銷。

url(r'^$','django.contrib.auth.views.login', {'template_name': 'base.html'}, name='login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': 'login'}, name='logout'),

您可以使用以下方法隱藏模板:

{% if user.is_authenticated %}
<html></html>
{% else %}
<html> add for logged out user</html>
{% endif %}

如果用戶注銷后單擊“后退”按鈕,這將防止用戶看到您的頁面。

編輯:在注銷功能中,您可以使用此功能,

from django.views.decorators.cache import cache_control

@cache_control(no_cache=True, must_revalidate=True)
 def your_function()
   #add your code
 return

用戶注銷后,這將清除緩存。

我使用一個簡單的腳本解決了該問題,該腳本在用戶注銷“清除”緩存時立即重新加載,這可能不是正確的方法,但對我有用,我將盡力尋找更好的方法去做吧。 如果有人知道,請分享。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM