dynamic values in yaml

Laurent Pointal laurent.pointal at laposte.net
Wed Aug 20 12:59:05 EDT 2014


raphinou at gmail.com wrote:

> Note that in my example the content to be inserted is not the result 
of a
> variable substitution, but the result of a call to a function. format
> doesn't seem to work in this case. And jinja2 doesn't seem to provide 
a
> straight forward solution either
> 
> Thx

Yoy may try it, setup an environment (dictionnary) with 'time' mapped 
to the time module, and render the template using this environment. 
Normally Jinja2 manage namespaces and function call.

Your template would be:

    filename: /tmp/backup_{{ time.strftime('%Y-%m-%d') }}.tgz

And the environment for rendering simply:

import time
env = { time: time }

http://jinja.pocoo.org/docs/templates/#other-operators







More information about the Python-list mailing list