Search code examples
pythondjangoadapterdjango-allauth

issue with custom adapter and django-allauth


I'm using django-allauth for my project and I'm trying to use a custom adapter to do some work on settings.LOGIN_REDIRECT_URL before the user is redirected after login, relevant code:

from allauth.account.adapter import DefaultAccountAdapter
from django.conf import settings

class DispersionAccountAdapter(DefaultAccountAdapter):

    def get_login_redirect_url(self, request):
        """ Retorna la URL por defecto para redirecciónar,

        esta lo hace formateando la cadena con el nombre del usuario.
        """
        if request.user.is_authenticated():
            return settings.LOGIN_REDIRECT_URL.format(
                username=request.user.username)
        else:
            return "/"

so, I did the changes on my settings.py as the documentation explains:

LOGIN_REDIRECT_URL = "/{username}/all"
ADAPTER = "dispersion.apps.adapter.DispersionAccountAdapter"
ACCOUNT_ADAPTER = "dispersion.apps.adapter.DispersionAccountAdapter"
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
LOGIN_URL = "/main/login"

So, when I run the server and try to login, I am redirected to http://127.0.0.1:8000/{username}/all instead of http://127.0.0.1:8000/jorge/all (if that were my user name). I'm not sure what's wrong with my set up. I tried the following without any problem at all:

$ python2 manage.py shell

In [1]: from dispersion.apps.adapter import DispersionAccountAdapter

In [2]: adapter = DispersionAccountAdapter()

Any advice or fix is very appreciated! :D


Solution

  • You are using 0.8.3 which does not support get_login_redirect_url yet -- support for this feature was added after 0.8.3.

    See: https://github.com/pennersr/django-allauth/blob/11ee262c9b9ec4923e8f3a34c71a05dad1dbccbb/ChangeLog#L1-L9

    If you need this functionality I suggest you use the development version over at github.