Skip to content

Instantly share code, notes, and snippets.

@abeyer
Created September 11, 2015 19:55
Show Gist options
  • Save abeyer/9b4e33bd70a48be71230 to your computer and use it in GitHub Desktop.
Save abeyer/9b4e33bd70a48be71230 to your computer and use it in GitHub Desktop.
splat json data on a jinja2 template from the command line
import json
import click
from jinja2 import Environment, FileSystemLoader, StrictUndefined
@click.command()
@click.argument('template_file')
@click.argument('data_file')
def main(template_file, data_file):
env = Environment(loader=FileSystemLoader(searchpath='.'), undefined=StrictUndefined)
tmpl = env.get_template(template_file)
data = json.load(open(data_file))
print tmpl.render(data)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment