Reputation: 443
I have a web2py application where I have written various modules which hold business logic and database related stuff. In one of the files I am trying to access auth.settings.table_user_name
but it doesn't work and throws and error as global name 'auth' is not defined
. If I write the same line in controller, it works. But I want it to be accessed in module file. Please suggest how do I do that.
Upvotes: 1
Views: 4407
Reputation: 1
I was getting a very similar error ("name 'auth' is not defined"). Had to add from django.contrib import auth
at the top of views.py and it worked.
Upvotes: 0
Reputation: 25536
In your model file, where you define auth
:
from gluon import current
auth = Auth(db)
current.auth = auth
Then in a module:
from gluon import current
def some_function():
auth = current.auth
....
For more details, see http://web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules.
Upvotes: 3