Let’s say, I created a template object (f.e. using environment.from_string(template_path)). Is it possible to check whether given variable name exist in created template?
I would like to know, if
template.render(x="text for x")
would have any effect (if something would be actually replaced by “text for x” or not). How to check if variable x exist?
From the documentation:
defined(value)
Return true if the variable is defined:
EDIT:
It seems you want to know if a value passed in to the rendering context. In that case you can use jinja2.meta.find_undeclared_variables, which will return you a list of all variables used in the templates to be evaluated.