开发者

How to get session from signal handler in Django

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜