python - Jinja2 and Flask: Pass variable into parent template without passing it into children -


let's have base template header in it, , content of header needs passed template.

<header>   logged in {{ name }} </header> 

this base template gets extended many pages. how can pass in variable without passing each individual child? example, don't want have this:

render_template("child1.html", name=user.name) render_template("child2.html", name=user.name) render_template("child3.html", name=user.name) etc... 

because knows how many child pages might have. doesn't feel dry enough.

i never render base template, children, don't know how else pass in data.

is there way this? should not using inheritance?

may suggest use global variable 'g' in flask. default available in jinja templates. don't need worry passing anywhere in base template or children. make sure set first when login

g.username = user.name 

then in templates, this:

you logged in {{ g.username }} 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -