2016-04-22 25 views
2

私は次のパラメータを使用してみましたが、それはここでは何もdjango allauthを使ってソーシャル・ログインした後、同じページにリダイレクトする方法は?

に影響を与えるdoesntのは、テンプレートここ

<div class="col-md-12 text-center"> 
        <a href="{% provider_login_url "facebook" method="oauth2" next='{{ request.path }}'%} "><img src = "{% static 'images/fbconnect.png' %}" height="45px" ></a> 
        <a href="{% provider_login_url "google" method="connect" next='{{ request.path }}'%} "><img src = "{% static 'images/g_login.png' %}" height="45px" ></a> 
        </div> 

ビュー

if request.POST.get('action') == 'login': 
       username_email = request.POST.get('user_email') 
       password = request.POST.get('password') 
       try: 
        the_user = User.objects.get(username=username_email) 
       except: 
        the_user = User.objects.get(email=username_email) 

       if the_user is not None: 
        user = authenticate(username=username_email , password=password) 
        if user is not None: 
         login(request , user) 
       return HttpResponse(json.dumps({'status' : 'True'})) 

答えて

0

リダイレクトparamはあなたので、あなたの例では動作しませんですあなたのビューでそれを使用していない場合は、単にHttpResponseを返すだけです。

ユーザーをリダイレクトするURLを指定してHttpResponseRedirectを返す必要があります。 allauthはこのここ実装方法を確認してください: https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py

を具体的に、リダイレクトURLをフェッチし、リダイレクトされRedirectAuthenticatedUserMixin、これらの2つの行を参照してください。

redirect_to = self.get_authenticated_redirect_url() 
response = HttpResponseRedirect(redirect_to) 
関連する問題