3
File size: 532 Bytes
5b82238
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
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)