How to get a session from a signal handler in Django

I implement a simple referral system. I have middleware that sets a session variable that identifies the caller. I have a model that associates a reference user with a specified user. I am trying to use the post_save signal from a User object to populate this model. How to access a session object from a post_save message handler?

+6
source share
2 answers

Cannot use a global variable depending on the stream .

But I'm not sure what you need. For my referral and invitation system, I simply register the user as usual, and after the user has been created, get the referral from the session. In almost all situations, it will be the same session.

If there is something in your session that prevents this, I would instead add it to the user creation form.

+1
source

You can find useful documentation when using sessions from views .

0
source

Source: https://habr.com/ru/post/896358/


All Articles