2017-01-18 5 views
0

djangoを使いこなし、企業Webポータルの現在の問題を解決しようとしました。スタッフアカウントでサイトにログインすると、ログインは正常に機能しますが、クライアントアカウントを使用するとERR :: TOO_MANY_REDIRECTSが返されます。このコードは、スタッフを使用して実行されDjangoクライアントのログインリダイレクトループ

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') 

redirect('home')が正常に動作しますが、クライアントでも、エラーメッセージを実行して文句を言わない、彼らはすぐにリダイレクトアカウントを占めています。

答えて

0

あなたは。ユーザーがそこに記録されていないためにも、最も可能性が高いリダイレクトページへ

+0

をリダイレクトしているが、ユーザがクライアントであるならば、何のリダイレクトが起こっていない、または私は何かが足りないのですか? – NSmith

関連する問題