Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Success URL redirect not working for custom view in django-allauth

I've created my own class LocalSignup which extends the base django-allauth SignupView class with my own form and my own validation logic. The problem is that on success I cannot get the view to redirect to anything but the django LOGIN_REDIRECT_URL in my settings.py. I have included a success_url field in my class based view; I have tried overriding the get_success_url function (see below); I have also tried passing my on success redirect using LocalSignup.as_view(success_url="/add_account_select/"). None have worked. Any ideas on what I'm doing wrong?

class LocalSignup(SignupView):
    form_class = AllAuthUserForm
    template_name = 'signup/social_login.html'
    success_url = '/add_account_select/'  #reverse_lazy('add_account_select')    

    def get_success_url(self):
        return '/add_account_select/'  #reverse('add_account_select')

    def dispatch(self, request, *args, **kwargs):
        # self.sociallogin = request.session.get('socialaccount_sociallogin')
        return super(LocalSignup, self).dispatch(request, *args, **kwargs)

    def form_valid(self, form):
        ret = super(LocalSignup, self).form_valid(form)
        ### MY FORM VALIDATION LOGIC
        return ret

    def get_context_data(self, **kwargs):
        ret = super(LocalSignup, self).get_context_data(**kwargs)
        ret.update(dict(username=self.sociallogin.account.user.first_name,
                        photo_url=self.sociallogin.account.get_avatar_url() ))
        return ret
like image 481
Hart Lambur Avatar asked Dec 05 '25 15:12

Hart Lambur


1 Answers

In the default view if there is "next" field in the sign-in form the view, allauth will automatically redirect to it.

<input id="login_redirect" type="hidden" name="next" value="#" />

complete form

      <form method="POST" action="{% url "account_login" %}">
        {% csrf_token %}
        {{form}}
        <input  type="hidden" name="next" value="/add_account_select/" />
        <button type="submit" class="btn btn-primary">Sign IN</button>
      </form>
like image 144
Ryu_hayabusa Avatar answered Dec 07 '25 12:12

Ryu_hayabusa