title: Import a Python module into a Jinja template?
body: <p>Is it possible to import a Python module into a Jinja template so I can use its functions? </p>
  
  <p>For example, I have a <strong>format.py</strong> file that contains methods for formatting dates and times. In a Jinja macro, can I do something <em>like</em> the following? </p>
  
  <pre><code>{% from 'dates/format.py' import timesince %}
  
  {% macro time(mytime) %}
  &lt;a title="{{ mytime }}"&gt;{{ timesince(mytime) }}&lt;/a&gt;
  {% endmacro %}
  </code></pre>
  
  <p>Because <strong>format.py</strong> is not a template, the code above gives me this error: </p>
  
  <pre><code>UndefinedError: the template 'dates/format.py' (imported on line 2 in 'dates/macros.html') does not export the requested name 'timesince'
  </code></pre>
  
  <p>...but I was wondering if there was another way to achieve this. </p>