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() )