Skip to content

Instantly share code, notes, and snippets.

@fmariluis
Created August 23, 2013 20:40
Show Gist options
  • Save fmariluis/6323783 to your computer and use it in GitHub Desktop.
Save fmariluis/6323783 to your computer and use it in GitHub Desktop.
Basic Jinja2 workflow
import jinja2
templateLoader = jinja2.FileSystemLoader(searchpath="templates")
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv.trim_blocks = True
template = templateEnv.get_template(TEMPLATE_FILE)
templateVars = {
"nombre_tabla": "ubicaciones",
"lista_campos": campos,
"inserts": inserts
}
output = template.render(templateVars)
with open((os.path.join(DIR_OUTPUT_SQL, 'datos.sql')), 'w') as f:
f.write(output.encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment