Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Django allauth signup "next" redirect URL

Suppose a user is on the page /some_url/ on a site with django-allauth. When clicking "Login" they get sent to a URL like:

/accounts/login/?next=/some_url/

If they are already a registered user, after logging in here, they get sent to the /some_url/, which is fine.

But if they're not registered, and they click "sign up", they get sent to:

/accounts/signup/?next=/some_url/

Suppose I want to send the user to some onboarding experience, at /onboarding/, straight after they sign up.

What's the simplest way to override allauth's default behaviour, and send the user to /onboarding/ even if a next=/some_url/ is specified?

like image 662
awidgery Avatar asked Mar 20 '15 14:03

awidgery


1 Answers

The simplest way would be to override the template account/signup.html with your own copy. If you examine that 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 part and change the value inside, the signup page will redirect to a specific page, even if you pass a next argument in the URL:

<input type="hidden" name="{{ redirect_field_name }}" value="/onboarding/" />
like image 152
Selcuk Avatar answered Oct 06 '22 02:10

Selcuk