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
current
object. Assuming you are using the standard nameauth
for theAuth
object, in a module, you can do:You can also explicitly add the user object as an attribute of
current
within a model file:And then in the module, you can access
current.auth_user
.As noted here, you should not assign properties of the
current
object to top level variables or class attributes within the module (this is because thecurrent
object 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
auth
object to your functions or classes from the module. For example, in a module: