I have managed to call python functions from jinja2 by using custom filters, but I can only seem to call functions with one or more parameters. In the following I have had to pass a junk parameter in order to treat ctest as a function rather than a variable.
It also doesn't work if I just call {{ ctest() }}
.
Is there a different way to force this to be a function call or should I be using a different approach?
code:
def ctest(stuff):
return "yeah!"
template_env = jinja2.Environment (loader = jinja2.FileSystemLoader(template_file_root))
#custom filters
template_env.filters['ctest'] = ctest
template:
Working? {{ junk|ctest }}
output:
working? yeah!