Skip to content

Instantly share code, notes, and snippets.

@selivan
Created March 5, 2021 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selivan/bd0df550920fc396f24f4e10185fb063 to your computer and use it in GitHub Desktop.
Save selivan/bd0df550920fc396f24f4e10185fb063 to your computer and use it in GitHub Desktop.
Python3 script to render jinja2 template. Requirements: pip install jinja2
#!/usr/bin/env python3
from jinja2 import Template
import sys
if len(sys.argv) < 3:
print(f'Usage: sys.argv[0] template_file output_file')
template_file = sys.argv[1]
out_file = sys.argv[2]
raw_template = open(template_file, 'r').read()
tm = Template(raw_template)
rendered_template = tm.render()
open(out_file, 'w').write(rendered_template)
print(f'Template: {template_file}\nRendered: {out_file}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment