문제

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"

도움이 되었습니까?

해결책

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top