Access variable in Jinja file from python module

32 Views Asked by At

I have a jinja file, result.j2 which contain a variable defined as below :

{% set file_name = 'foo' %}

I am trying to find a way to access this variable from python module. So, lets say I have access.py module and I would like to import the value 'foo' in access.py so I can use it.

I tried with below :

from jinja2 import Environment, FileSystemLoader

env = Environment(loader = FileSystemLoader("./"), trim_blocks=True, lstrip_blocks=True)

template = env.get_template("./result.j2")

print(template)

however, this is not working. I think the issue that the variable is under set command and no render for this file

0

There are 0 best solutions below