I am working in a web2py application, where I need to access current user in modules, so is there any possibility to access current user in web2py modules, and yes then How can I access this?
Thanks
I am working in a web2py application, where I need to access current user in modules, so is there any possibility to access current user in web2py modules, and yes then How can I access this?
Thanks
Copyright © 2021 Jogjafile Inc.
One option is to use the thread local
currentobject. Assuming you are using the standard nameauthfor theAuthobject, in a module, you can do:You can also explicitly add the user object as an attribute of
currentwithin a model file:And then in the module, you can access
current.auth_user.As noted here, you should not assign properties of the
currentobject to top level variables or class attributes within the module (this is because thecurrentobject is local to each thread, but such assignments will only take place once, when the module is first imported).Another option is simply to pass the
authobject to your functions or classes from the module. For example, in a module: