askrobots / dbbasic-web
Public
A Unix-style Python web framework: filesystem routing, flat files, messages and cron, with CGI's simplicity at modern speed.
Dan Quellhorst
Replace multipart parser with stdlib-only implementation
eb957a2
9 months, 2 weeks ago
History
templating.py · 427 bytes · 14 lines
| 1 | """Template rendering with Jinja2""" |
| 2 | from jinja2 import Environment, FileSystemLoader, select_autoescape |
| 3 | from .settings import TEMPLATES_DIR |
| 4 | |
| 5 | env = Environment( |
| 6 | loader=FileSystemLoader([str(TEMPLATES_DIR)]), |
| 7 | autoescape=select_autoescape(["html", "xml"]), |
| 8 | ) |
| 9 | |
| 10 | |
| 11 | def render(template_name: str, **ctx) -> str: |
| 12 | """Render a template with context""" |
| 13 | tmpl = env.get_template(template_name) |
| 14 | return tmpl.render(**ctx) |