Differences between revisions 1 and 2
Revision 1 as of 2021-12-22 16:03:01
Size: 558
Editor: Burathar
Comment:
Revision 2 as of 2021-12-22 16:04:30
Size: 588
Editor: Burathar
Comment:
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
> > My name is Alex
Line 25: Line 25:
> > My name is Alex

Debugging in python3 shell

Without custom enviroment:

   1 from jinja2 import Template
   2 
   3 template_str = "My name is {{name}}"
   4 obj = {'name': 'Alex'}
   5 
   6 print(Template(template_str).render(obj))
   7 > My name is Alex

Using a custom enviroment:

   1 from jinja2 import Environment
   2 from jinja2_ansible_filters import AnsibleCoreFiltersExtension
   3 
   4 env = Environment(extensions=[AnsibleCoreFiltersExtension])
   5 template_str = "My name is {{name}}"
   6 obj = {'name': 'Alex'}
   7 
   8 print(env.get_template(template_str).render(obj))
   9 > My name is Alex

Howto/Python3/jinja2 (last edited 2021-12-22 16:04:30 by Burathar)