Spaces:
Sleeping
Sleeping
Download templating.py from Corin1998/IR_ESG_REPORTER2: direct link, hf CLI and curl.
- Browser
- Download file 532 Bytes
-
https://huggingface.co/spaces/Corin1998/IR_ESG_REPORTER2/resolve/main/templating.py
- Command line
-
hf download hf://spaces/Corin1998/IR_ESG_REPORTER2/templating.py
-
curl -L -o templating.py https://huggingface.co/spaces/Corin1998/IR_ESG_REPORTER2/resolve/main/templating.py
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) | |