问题描述
我正在使用django构建登录和注销页面,下面是我的代码
I am using django to build a login and logout page , below are my codes
urls.py
from django.conf.urls.defaults import *
from django.conf import settings
from django.core.urlresolvers import reverse
urlpatterns = patterns('',
url(r'^$', 'learn_django.views.home_page'),
url(r'^login/$', 'learn_django.views.login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'logout.html'}),
)
views.py
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth import authenticate, login as main_login, logout as main_logout
def home_page(request):
return render_to_response("home_page.html")
def login(request):
.....
.....
return render_to_response("login.html")
logout.html
{% extends 'base.html' %}
{% block title %}Logout Page{% endblock %}
{% block body %}
<div>
<p style='color:#092E20;font-size:25px;font-weight:bold;padding-top:20px;padding-left:15px;'>
You have been successfully logged out......
</p>
<p>Redirecting to login page.....</p>
</div>
{% endblock %}
所以在上面的代码中,我将有一个登录URL,该URL将显示登录表单,并在成功登录后重定向到另一个URL,效果很好
So in the above codes, i will have a login url which will display a login form and redirects to another url after successfull login which is working fine
另外,我将提供一个我正在使用django built-in logout view
的注销URL,方法是为它提供模板logout.html
,该模板也可以正常工作,并且当我单击注销URL时成功显示上述html代码
Also i will have a logout url for which i am using the django built-in logout view
, by supplying it a template logout.html
which is also working fine and displaying the above html code successfully when i clicked the logout url
所以现在我想在显示注销页面后(一段时间后...)重定向到登录页面.我的意思是,首先注销视图应呈现logout.html
代码,其次应重定向到登录页面....
So now i want to redirect to the login page after displaying the logout page(after some time period....). I mean first the logout view should render the logout.html
code and next should redirect to login page ....
任何人都可以让我知道如何在如上所述渲染logout.html之后重定向到登录html页面...
Can anyone please let me know how to redirect to login html page after rendering logout.html as above ......
推荐答案
将其放入您的logout.html
Put this in your logout.html
<script>
function redirect(){
window.location.href = "supply_url_here";
}
setTimeout(redirect, 2000); //2000 is equivalent to 2 seconds
</script>
这篇关于成功注销后重定向django内置注销视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!