use the next of the url in the custom login view

Viewed 23

I have this customized views login the problem is that when I have a view with the decorators login the url with next does not work but it redirects me to the page I marked in my customized views

class Login(auth_views.LoginView):
    
    def get_success_url(self):
        if self.request.user.is_superuser:
            return reverse('dashboard')
        else:
            return reverse('homepage')
1 Answers

You have to let loginview to redirect in case where you want to use the next param:

class Login(auth_views.LoginView):
    
    next_page = reverse('homepage')

    def get_success_url(self):
        if self.request.user.is_superuser:
            return reverse('dashboard')
        else:
            return super().get_success_url()

With this code, your view will try to find a next page with post or get param send to the view, and if it finds nothing, the view use the next_page attribute fore redirecting user.

you can see the behaviour of the LoginView here: https://github.com/django/django/blob/main/django/contrib/auth/views.py

Related