a jinja2 extension to access to system environment variables
Project description
What is it ?
This is a jinja2 extension to access to system environment variables. It is usefull if you have dynamically generated variable names.
Syntax
The syntax is {% raw %}{{ 'ENV_VAR'|getenv }}{% endraw %}
to access to the ENV_VAR
environment
variable. Don't forget the quotes around ENV_VAR
!
If you want to provide a default value to avoid an exception if the corresponding
environment variable does not exist, you can use the following syntax:
{% raw %}{{ 'ENV_VAR'|getenv('default_value') }}{% endraw %}
.
Examples
from jinja2 import Template, Environment
# We load the extension in a jinja2 Environment
env = Environment(extensions=["jinja2_getenv_extension.GetenvExtension"])
# For the example, we use a template from a simple string
template = env.from_string("the value of HOME environment variable is: "
"{% raw %}{{ 'HOME'|getenv }}{% endraw %}")
result = template.render()
# [...]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for jinja2_getenv_extension-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43484804b54f063a3d2e3592861f3e867fecbff733f4c9eb35e9fc167fb25815 |
|
MD5 | a23587d8d805ed13a776fba5c051b27d |
|
BLAKE2b-256 | 004543f40f0aa6e3eb96fc97a964a23cb8c684a0d6f0999fc874b3666835aff1 |
Close
Hashes for jinja2_getenv_extension-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6c1e3e11f56c9b15058fa442028ea4703063c2d89157ea946a25ff9c8e56f8c |
|
MD5 | cb9de68c944003f12e3025e766cf28c3 |
|
BLAKE2b-256 | 83821da492511b6260173b4754ae0253c11b38aecff9624c9c1efb761768c292 |