As I understand the g variable in Flask, it should provide me with a global place to stash data like holding the current user after login. Is this correct?
I would like my navigation to display my user's name, once logged in, across the site.
My views contain
from Flask import g #among other things
During login, I assign
user = User.query.filter_by(username = form.username.data).first()
if validate(user):
session['logged_in'] = True
g.user = user
It doesn't seem I can access g.user. Instead, when my base.html template has the following...
<ul class="nav">
{% if session['logged_in'] %}
<li class="inactive">logged in as {{ g.user.username }}</li>
{% endif %}
</ul>
I get the error:
jinja2.exceptions.UndefinedError
UndefinedError: 'flask.ctx._RequestGlobals object' has no attribute 'user'
The login otherwise works fine. What am I missing?