▲ | kazinator 8 days ago | |||||||||||||||||||||||||
I can easily end up unsafely processed. It's a footgun. And why would you be validating HTML on the fly, when it's coming from your program, not as an input into it. Even if you can do it at program startup once for each template, it's still pointless overhead. The whole thing is wrongheaded; exactly the kind of stove-pipe people end up inventing when they don't have metaprogramming. | ||||||||||||||||||||||||||
▲ | zahlman 8 days ago | parent | next [-] | |||||||||||||||||||||||||
> I can easily end up unsafely processed. No, that isn't how it works. The unprocessed version is not a `str` instance and doesn't implement `__str__`: > This is because Template instances are intended to be used by template processing code, which may return a string or any other type. There is no canonical way to convert a Template to a string. If you tried to use the Template directly as if it were a string, you'd get either a TypeError or completely malformed HTML (the `repr` of the Template instance, which would look very different). >And why would you be validating HTML on the fly You wouldn't be; you'd be escaping user-generated content that tries to break a page by including HTML markup. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | davepeck 8 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
> I can easily end up unsafely processed I’m curious how? | ||||||||||||||||||||||||||
▲ | pphysch 8 days ago | parent | prev [-] | |||||||||||||||||||||||||
You don't have to add HTML validation to your processing func, but you brought up invalid syntax up as an issue with string templating. > The whole thing is wrongheaded; exactly the kind of stove-pipe people end up inventing when they don't have metaprogramming. Python has many metaprogramming features. I don't think you understand this feature much less its motivation. How else would you go about adding language support for e.g. HTML and SQL within Python? | ||||||||||||||||||||||||||
|