开发者

Pylons: Set global variable for Authkit user

开发者 https://www.devze.com 2022-12-24 21:26 出处:网络
How can I can set a global var开发者_运维知识库iable for the username of the logged-in user? At the moment i have the following code in all my controllers to get the username. I rather set it as a glo

How can I can set a global var开发者_运维知识库iable for the username of the logged-in user? At the moment i have the following code in all my controllers to get the username. I rather set it as a global variable if possible.

request.environ.get("REMOTE_USER")

I tried putting the same code in the app_globals.py file but it gave me the following error message: "No object (name: request) has been registered for this thread"


There is no single "logged-in user" if you're serving requests on multiple threads -- by setting a single global variable the threads would trample upon each other and end up very very confused on who "the logged-in user" actually is. There is (at most;-) a single logged-in user per request, so keeping that info in the request object seems vastly preferable;-).

0

精彩评论

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

关注公众号