On Dec 11, 2010, at 7:18 AM, Vikram wrote:
> 
> I could not able to connect to database giving the below error.
> 
> Traceback (most recent call last):
>  File "/home/vikramt/web2py/gluon/restricted.py", line 188, in
> restricted
>    exec ccode in environment
>  File "/home/vikramt/web2py/applications/myapp/controllers/
> default.py", line 66, in <module>
>  File "/home/vikramt/web2py/gluon/globals.py", line 96, in <lambda>
>    self._caller = lambda f: f()
>  File "/home/vikramt/web2py/applications/myapp/controllers/
> default.py", line 24, in check
>    roles=myrole.mysession(request.vars.ldap)
>  File "applications/myapp/modules/checkrole.py", line 4, in mysession
>    role=db.user(role,ldap=username)
> NameError: global name 'db' is not defined
> 
> I have tried all sorts but could not. Could you please help me

Globals that are defined in your models are visible to controllers, but not to 
modules. I'm not sure what the best practice would be (probably depends on your 
specific application), but you can either move checkrole.py to models (and not 
import it) or pass globals to it as function arguments.

Reply via email to