Created
February 14, 2014 20:14
-
-
Save vicalejuri/9008362 to your computer and use it in GitHub Desktop.
Jinja2 Simple Render Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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