Skip to content

Instantly share code, notes, and snippets.

@vicalejuri
Created February 14, 2014 20:14
Show Gist options
  • Save vicalejuri/9008362 to your computer and use it in GitHub Desktop.
Save vicalejuri/9008362 to your computer and use it in GitHub Desktop.
Jinja2 Simple Render Example
import os
from jinja2 import FileSystemLoader, Environment
template_path = os.getcwd()
# Load jinja
jinja_loader = FileSystemLoader( template_path )
jinja_env = Environment( loader=jinja_loader )
# Get the template and render it using `myvars`
myvars = {'SOME_VAR': 1, 'OTHER_VAR': 'Porra' }
tmpl_file = jinja_env.get_template( 'template_file.py' )
rendered_file = tmpl_file.render( **myvars )
# To write to another file, use `file`
out_file = file('template_file_result.py','w')
out_file.write( rendered_file )
out_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment