Sometimes, you don't want to prefix whatever you are sharing in your thread local with g. for some reason. To solve this problem, you can create your own local-type proxy objects with:
from werkzeug.local import LocalProxy
whatever = LocalProxy(lambda: g.whatever)
Of course, this can be used for other things besides just g.
from werkzeug.local import LocalProxy
method = LocalProxy(lambda: request.method)
Now that Werkzeug 0.6.1 is out, it's really more of an AnythingProxy than just a LocalProxy.
This snippet by LeafStorm can be used freely for anything you like. Consider it public domain.
Comments
Use case by LeafStorm on 2010-05-07 @ 22:23
I discovered this neat little trick after I had written a bunch of code that saved directly to session. After I decided to use an external session store (actually CouchDB), I didn't want to rewrite it all, so I created a LocalProxy named session and switched the import.