File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ ## What is it ?
2+
3+ This is a [ jinja2] ( http://jinja.pocoo.org/ ) extension to access to system
4+ environment variables. It is usefull if you have dynamically generated
5+ variable names.
6+
7+ ## Syntax
8+
9+ The syntax is ` {% raw %}{{ 'ENV_VAR'|getenv }}{% endraw %} ` to access to the ` ENV_VAR ` environment
10+ variable. Don't forget the quotes around ` ENV_VAR ` !
11+
12+ If you want to provide a default value to avoid an exception if the corresponding
13+ environment variable does not exist, you can use the following syntax:
14+ ` {% raw %}{{ 'ENV_VAR'|getenv('default_value') }}{% endraw %} ` .
15+
16+ ## Examples
17+
18+ ``` python
19+
20+ from jinja2 import Template, Environment
21+
22+ # We load the extension in a jinja2 Environment
23+ env = Environment(extensions = [" jinja2_getenv_extension.GetenvExtension" ])
24+
25+ # For the example, we use a template from a simple string
26+ template = env.from_string(" the value of HOME environment variable is: "
27+ " {% raw %}{{ 'HOME'|getenv }} {% endraw %}" )
28+ result = template.render()
29+
30+ # [...]
31+ ```
32+
You can’t perform that action at this time.
0 commit comments