开发者

How to get session from signal handler in Django

开发者 https://www.devze.com 2023-04-01 08:38 出处:网络
I\'m implementing a simple ref开发者_StackOverflowerral system. I have middleware which sets a session variable identifying the referring user. I have a model which ties a referring user to the referr

I'm implementing a simple ref开发者_StackOverflowerral system. I have middleware which sets a session variable identifying the referring user. I have a model which ties a referring user to the referred user. I'm trying to use the post_save signal from the User object to populate this model. How do I access the session object from within the post_save signal handler?


There is not way without using a thread specific global variable.

But I'm not sure you need to. For my referral and invite system I just have the user register as normal and after the user has been created, get the referral out of the session. In almost all situations it will still be the same session.

If there is something about your session that prevents that, I would instead add it to the create user form.


You may find useful documentation on using sessions out of views.

0

精彩评论

暂无评论...
验证码 换一张
取 消