Why second user login redirects me to /accounts/profile/ url?

django.contrib.auth.views.login redirects you to accounts/profile/ right after you log in.
You may want to set LOGIN_REDIRECT_URL inside your settings.py file to anything you like..


check your login.html

<form method="post" action=".">
    ~blah~
    <input type="hidden" name="next" value="/"><!-- login.html must send "next" parameter, and "next" parameter value is url that you want to redirect.  -->
    ~blah~
</form>

good luck~


Explained in doc:

(accounts/profile/ is ...) The URL where requests are redirected after login when the contrib.auth.login view gets no next parameter.

Because you are yet authenticated your request is redirected to this url. To avoid redirect you should logout user before send it to user/login, create your custom login view or append Next parameter.


All of this did not work for me. I used a JavaScript solution:

In the login.html (where the social login buttons are) I put this script which stores next in local storage::

<script>
// Check for local storage
if (typeof(Storage) !== "undefined") {
    var h = window.location.href;
    if (h.indexOf("next") > 0){
        var tokens = h.split("=");
        var nextUrl = tokens[1];

        for(i = 2;i< tokens.length;i++){
            nextUrl += ("=" + tokens[i]);
        }
        localStorage.setItem("next",nextUrl);

    }
}
</script>

In the page where the users are being redirected to I used the following script to redirect:

$(document).ready(function () {

    // Check for local storage
    if (typeof(Storage) !== "undefined") {
            var nextUrl = localStorage.getItem("next");
            if (nextUrl.length > 0){
                localStorage.setItem("next","");
                window.location = nextUrl;
            }
    }
    else {
        // Sorry! No web storage support..
    }
}