nginx-configurator/nginx_configurator/templating.py

16 lines
416 B
Python
Raw Normal View History

2023-11-04 23:02:34 +01:00
import pkgutil
from jinja2 import Environment, FunctionLoader, select_autoescape
def load_template(name):
"""
Loads file from the templates folder and returns file contents as a string.
See jinja2.FunctionLoader docs.
"""
return pkgutil.get_data(f"{__package__}.templates", name).decode("utf-8")
jinja = Environment(
loader=FunctionLoader(load_template), autoescape=select_autoescape()
)