Skip to content

Instantly share code, notes, and snippets.

@greencoder
Created May 4, 2021 15:09
Show Gist options
  • Save greencoder/7906ec8e27f940db42c5eb362c1a1708 to your computer and use it in GitHub Desktop.
Save greencoder/7906ec8e27f940db42c5eb362c1a1708 to your computer and use it in GitHub Desktop.
Jinja2 Setup Example
import arrow
import jinja2
# Set up the template engine
template_loader = jinja2.FileSystemLoader('./templates')
template_env = jinja2.Environment(loader=template_loader)
template_env.filters['fmt_date'] = lambda v: arrow.get(v, fmt).format(fmt)
# Write the file
template = template_env.get_template('template.html')
html = template.render(data={})
pathlib.Path('index.html').write_text(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment