【发布时间】:2015-08-30 03:05:53
【问题描述】:
在我的 django web 应用程序中注销用户后,重定向的主页仍然显示“注销”按钮而不是“使用 Facebook 登录”。在以下代码中,我按照 django 文档注销用户并将页面重定向到主页,即 base.html。注销后,我的网络应用程序似乎仍有 user.is_authenticated 为 True ?我错过了什么?
我在网上找不到任何有用的提示。非常感谢任何评论。
这是我的模板 html 的一部分
<div class="navbar-form navbar-right">
{% if user.is_authenticated %}
<a id="logout" href="/accounts/logout" class="btn btn-success">Logout</a>
{% else %}
<a id="facebook_login" href="/accounts/facebook/login" class="btn btn-success">Sign in with Facebook</a>
{% endif %}
</div>
这是我的 urls.py
url(r'^$', 'homepage.views.home', name='home'),
url(r'^accounts/', include('allauth.urls')),
url(r'^accounts/logout/$', 'homepage.views.logout', name='logout'),
这是我的主页/views.py
# Create your views here.
def home(request):
return render(request, "base.html", {})
# ensure only logged in users can access the view.
@login_required
def logout(request):
logout(request)
# Take the user back to the homepage.
return redirect('home')
【问题讨论】: