I'm using a function in a web2py module which should raise an HTTP exception. For most functions (e.g. T) I do
from gluon import current
def f(x):
return current.T(x)
But I can't do e.g. raise current.HTTP(...): I get
<type 'exceptions.AttributeError'> 'thread._local' object has no attribute 'HTTP'
So is there any way to use HTTP() in a web2py module?
The best option is probably just to import
HTTPin the module:Alternatively, you can explicitly add the
HTTPobject to thecurrentobject. In a model file or in the relevant controller:Then you will be able to access
current.HTTPin any module where you importcurrent.Finally, the entire web2py global environment is available via the
current.globalenvdictionary, so in any module where you importcurrent, you can do:web2py only adds the
request,response,session,cache, andTobjects directly tocurrent, so if you want to access any other objects from the global environment, you must either add them explicitly or usecurrent.globalenv.