I am currently using python social auth to login users into my Django app and show a tutorial upon first user creation. I've tried this so far but request does not work in pre_save signals. Is there another way to do this?
@receiver(pre_save, sender=User)
def show_tutorial(sender, instance=None, **kwargs):
# For first time creation of user display tutorial
if instance._state.adding:
print ('USER CREATED')
request.session['first_login'] = True
EDIT: I tried the following code in my views but once logging in, the print statement never logged in the terminal.
def after_user_created(request, user, **kwargs):
user, created = User.objects.get_or_create(user=user)
if created:
request.session['first_login'] = True
print('FIRST LOGIN')
You cannot do it. You should not do it even if you could do it. Let's do the operation on "request" as much as possible on "view". like this.
def create_view(request):
user, created = User.objects.get_or_create(id=xxx)
if created:
request.session['first_login'] = True
UPDATE
Add a solution that assumes using "social-app-django".
① set settings.SOCIAL_AUTH_NEW_USER_REDIRECT_URL
NEW_USER_REDIRECT_URL=/new/user/view
② Update session with new user view。
def new_user_view(request):
request.session['first_login'] = True