django页面重定向成功登录 [英] django page redirect on success login
问题描述
实际上在 http://127.0.0.1:8000/login/ 显示我的登录页面
现在我想要正确登录,它将重定向到我的索引页。
没有确切的方式。
def login(request):
template =../templates /admin/login.html
data = {
}
user = auth.authenticate(username ='aa',password ='bb')
如果用户不是无和user.is_active:
template =../templates/admin/index.html
auth.login(request,user)
return HttpResponseRedirect(/ login / index $
return render_to_response(template,data,
context_instance = RequestContext(request))
thanx提前。
如果您被自动重定向,那么您的缩进关闭。你不幸运,但是你写的代码没有触发一个 IndentationError
。
我的猜测是你复制从文档中粘贴并添加到代码中?
我会检查以确保没有标签和空格混合。
这是一个固定的,从POST请求中提取信息。
def login(request):
template =../templates/admin/login.html
data = {}
如果request.method =='POST':
user = auth.authenticate( username = request.POST.get('username'),
password = request.POST.get('password'))
如果用户不是None和user.is_active:
auth。
返回HttpResponseRedirect(/ login / index /)
返回render_to_response(template,data,context_instance = RequestContext(request))
im not getting exactly.. actually on httpresponse redirect it show nothing. actually on http://127.0.0.1:8000/login/ in show my login page now i want on correct login it will redirect to my index page. dont the exact way.
def login(request):
template = "../templates/admin/login.html"
data = {
}
user = auth.authenticate(username='aa', password='bb')
if user is not None and user.is_active:
template = "../templates/admin/index.html"
auth.login(request, user)
return HttpResponseRedirect("/login/index/")
return render_to_response( template, data,
context_instance = RequestContext( request ) )
thanx in advance.
If you are being redirected automatically, then your indentation is off. You got unlucky and however you wrote your code didn't trigger an IndentationError
.
My guess is you copy and pasted from the documentation and added to the code?
I'd check to make sure you don't have tabs and spaces mixed up.
Here's a fixed one that pulls information from the POST request.
def login(request):
template = "../templates/admin/login.html"
data = {}
if request.method == 'POST':
user = auth.authenticate(username=request.POST.get('username'),
password=request.POST.get('password'))
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect("/login/index/")
return render_to_response( template, data, context_instance = RequestContext( request ) )
这篇关于django页面重定向成功登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!