Is it possible to import a Python module into a Jinja template so I can use its functions?
For example, I have a format.py file that contains metho
Just pass the function into the template, like so
from dates.format import timesince
your_template.render(timesince)
and in the template, just call it like any other function,
{% macro time(mytime) %}
{{ timesince(mytime) }}
{% endmacro %}
Functions are first-class citizens in python, so you can pass them around just like anything else. You could even pass in a whole module if you wanted.