3 / templating.py
Corin1998's picture
Upload 17 files
5b82238 verified
raw
history blame contribute delete
532 Bytes
from jinja2 import Environment, FileSystemLoader, select_autoescape
from pathlib import Path
def get_env(templates_dir: str):
here = Path(__file__).resolve().parent
searchpaths = [templates_dir, str(here / "templates"), str(Path().resolve() / "templates")]
env = Environment(loader=FileSystemLoader(searchpaths), autoescape=select_autoescape(["html","xml"]))
return env
def render(env, template_name: str, context: dict) -> str:
template = env.get_template(template_name)
return template.render(**context)