Python Django客户端登录重定向循环
django新手,尝试解决公司门户网站的当前问题。使用员工帐户登录站点时,登录工作正常,但使用客户端帐户会返回ERR::TOO_MANY_重定向Python Django客户端登录重定向循环,python,django,redirect,Python,Django,Redirect,django新手,尝试解决公司门户网站的当前问题。使用员工帐户登录站点时,登录工作正常,但使用客户端帐户会返回ERR::TOO_MANY_重定向 def user_login(request): # Like before, obtain the context for the user's request. context = RequestContext(request) form = AuthenticationForm() # If the request is a HTTP POST,
def user_login(request):
# Like before, obtain the context for the user's request.
context = RequestContext(request)
form = AuthenticationForm()
# If the request is a HTTP POST, try to pull out the relevant information.
if request.method == 'POST':
# Gather the username and password provided by the user.
# This information is obtained from the login form.
username = request.POST['username']
password = request.POST['password']
# Use Django's machinery to attempt to see if the username/password
# combination is valid - a User object is returned if it is.
try:
user = authenticate(username=username, password=password)
except LockedOut:
messages.error(request, 'You have been locked out because of too many login attempts. Please try again in 10 minutes.')
# If we have a User object, the details are correct.
# If None (Python's way of representing the absence of a value), no user
# with matching credentials was found.
else:
if user:
# Is the account active? It could have been disabled.
if user.is_active:
# If the account is valid and active, we can log the user in.
# We'll send the user back to the homepage.
login(request, user)
if request.user.is_client:
messages.error(request, 'Something is not working correctly.')
elif request.user.is_staff:
return redirect('home')
else:
# An inactive account was used - no logging in!
messages.error(request, 'Your account is disabled.')
else:
messages.error(request, 'The credentials you entered are invalid.')
# Bad login details were provided. So we can't log the user in.
# The request is not a HTTP POST, so display the login form.
# This scenario would most likely be a HTTP GET.
# No context variables to pass to the template system, hence the
# blank dictionary object...
#return render_to_response('administrative/login.html', {'form': form}, context)
return redirect('administrative/login.html')
当使用员工帐户运行此代码时,
重定向(“主页”)
工作正常,但客户端帐户甚至不会运行错误消息,它们只是立即重定向。您正在重定向到一个也重定向的页面,很可能是因为该用户未登录。但如果该用户是客户端,则不会发生重定向,或者我是否遗漏了什么?