Question

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"

Was it helpful?

Solution

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;-).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow