Flask - access to the configuration variable in the template

I am using Flask version 0.7. I saved the path of the static content in the configuration file and loaded it with

app.config.from_envvar(<file_name>) 

Can I access this configuration variable in a template without passing variables through the view?

+44
python flask jinja2
Aug 18 2018-11-11T00
source share
1 answer

There are several global variables that are flagged by default in the context of templates ( here is a complete list), one of them is config , which allows you to access the application configuration from templates. As a dictionary, it can be accessed using the syntax config['MY_CONFIGURATION'] or config.MY_CONFIGURATION (this syntax for accessing dict elements is specific to Jinja).

On the other hand, if you want to pass arbitrary data to your templates without having to pass them explicitly in each view, you will have to use contextual processors .

+74
Aug 18 '11 at 8:44
source share
β€” -



All Articles