Set a global variable for all mako templates using bottle? -


i'm using bottle beaker session middleware. i'd include session object in mako templates without specifying when rendering:

instead of this:

return mako_template("myview", {      "session" : bottle.request.environ.get('beaker.session')  }) 

just this:

return mako_template("myview") 

is possible? if so, how?

i don't know mako templates, bottle simpletemplates can use basetemplate.default:

bottle.basetemplate.defaults['session'] = bottle.request.environ.get('beaker.session') 

however, since setting @ application instantiation time, bottle.request may not valid. may need turn lazy evaluation when value requested.

perhaps basetemplate.defaults gets fed mako templates, or maybe mako provides similar mechanism setting defaults?

i hope helps point in right direction.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -