t-string HTML renderer ignores `:.2f` and escapes nested templates as raw text
I’m switching my HTML helpers from f-strings to t-strings so user input gets escaped automatically. Escaping works, but number formatting is gone. When I put one template inside another, the inner template comes out as an escaped object dump instead of HTML. from string.templatelib import Template, Interpolation import html def render(template: Template) -> str: parts = [] for item in template: if isinstance(item, Interpolation): parts.append(html.escape(str(item.value))) else: parts.append(item) return "".join(parts) name = "<b>Rahum</b>" price = 19.999 row = t"<td>{name}</td><td>${price:.2f}
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.