简体   繁体   English

塔:为Authkit用户设置全局变量

[英]Pylons: Set global variable for Authkit user

How can I can set a global variable 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" 我尝试将相同的代码放入app_globals.py文件中,但它给了我以下错误消息:“该线程没有注册任何对象(名称:请求)”

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;-). (至多;-) 每请求的单一登录的用户,因此保持在请求对象信息似乎远远优于;-)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM