2

I have a django project in which there is a UserProfile having a OneToOne to the User model. It uses django-allauth for registration.

I am accepting registration via account and social account. Upon signing up, i want the user to be redirected to a page to create the UserProfile for that user account.

How could i do that ?

I have read, there is 1 signal called user_signed_up, can it be used to redirect the user to certain page ? I tried this code below, but it doesn't redirect me to the page i wanted.

@receiver(user_signed_up, dispatch_uid="some.unique.string.id.for.allauth.user_signed_up")
def do_stuff_after_sign_up(sender, **kwargs):
    request = kwargs['request']
    user = kwargs['user']
    return redirect ('/test/')

any help will be greatly appreciated. thanks :)

  • I hope that is not the indentation of your actual code – yuvi Oct 07 '13 at 10:21
  • hehe, oops i just copy and pasted it. thanks for the comment @yuvi – Reinaldo Wijaya Oct 07 '13 at 10:43
  • regarding your question, does this help you? http://stackoverflow.com/questions/13295603/decide-where-to-go-to-after-connecting-with-django-allauth – yuvi Oct 07 '13 at 11:40
  • 1
    This [answer](http://stackoverflow.com/a/18503210/805427) should help. – elssar Oct 08 '13 at 08:53
  • Hi @yuvi, thanks but not suitable actually. cause i want the profile page only accessed at the first time they signed up not everytime they logged in :) – Reinaldo Wijaya Oct 08 '13 at 09:32
  • hi @elssar,can i go to a certain view after receiving the user_signed_up signal ? – Reinaldo Wijaya Oct 08 '13 at 09:33
  • No, for that you will have to use the method that @yuvi linked. Just check whether the user has a profile or not in the view and take it from there. Or even better, use a middleware. – elssar Oct 08 '13 at 09:38

1 Answers1

0

I know its late but I hope future readers would find it helpful. :)

You need to raise an ImmediateHttpResponse like this:

from allauth.exceptions import ImmediateHttpResponse
from django.shortcuts import render

@receiver(user_signed_up, dispatch_uid="some.unique.string.id.for.allauth.user_signed_up") 
def do_stuff_after_sign_up(sender, **kwargs): 
    request = kwargs['request'] 
    user = kwargs['user'] 
    raise ImmediateHttpResponse(render(request, 'you_custom_profile.html', {'user': user}))
Ahtisham
  • 9,170
  • 4
  • 43
  • 57