Bottle py and Jinja2 global variable
Question: I am using bottle.py framework along with Jinja2 templates in a new
application.

Whenever a user logs into the application I would like to add a new global
Jinja2 variable with the name of the active user, so in a partial template
(the header) I can display this name.

In my python (bottle) file I've tried several things according to what I
googled so far, but no success yet.

This is the last thing I tried inside a function:

    
    
    import jinja2
    env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
    env.globals['myglobal'] = 'My global'
    #env.globals.update({'myglobal': 'My global'})
    

But, when putting this into the header template: {{myglobal}} it simply
doesn't show up.

Since this is my first time with bottle and jinja2 anyone knows how can
achieve this?


Answer: I have a similar setup, and this works for me using the BaseTemplate built
into bottle:

    
    
    from bottle import BaseTemplate
    BaseTemplate.defaults['myglobal'] = 'My global'
    

