Override Django allauth "next" redirect URL

Suppose the user is on the page /some_url/ on the site with django-allauth. When you click Sign In, they are sent to the URL, for example:

 /accounts/login/?next=/some_url/ 

If they are already registered, after logging in they are sent to /some_url/ , which is good.

But if they are not registered, and they click "Register", they are sent to:

 /accounts/signup/?next=/some_url/ 

Suppose that I want to send the user to some experience on board, to /onboarding/ , immediately after registration.

What is the easiest way to override allauth's default behavior and send the user to /onboarding/ even if next=/some_url/ ?

+7
django django-allauth
source share
1 answer

The easiest way is to override the account/signup.html your own copy. If you study this template, you will see the following section:

 {% if redirect_field_value %} <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" /> {% endif %} 

If you remove the if / endif and change the value inside, the registration page will be redirected to a specific page, even if you pass the next argument in the URL:

 <input type="hidden" name="{{ redirect_field_name }}" value="/onboarding/" /> 
+10
source share

All Articles