home ~ projects ~ socials

Use Jinja For Template Output In Python

from jinja2 import Environment, select_autoescape

env = Environment(
    autoescape=select_autoescape()
)

template = env.from_string("""
Hello, {{ name }}!
""")

output = template.render(name="World")

print(output)
Output:
Hello, World!
-- end of line --