Writing a Jinja-inspired template library in Python
notes.eatonphil.com
notes.eatonphil.com
I helped design Django's template language and I now think we took keeping it restrictive a bit too far though - these days I prefer working with Jinja because it has better support for complex expressions and lets you call functions within your templates. That does mean it requires a bit more discipline to use responsibly though, but being able to control which functions are exposed to the template context helps a lot there.
When using jinja2 for website builders, it just feels like a poor version of old school php.
I’ve also seen it used for generating json/yaml config files, which to me is absolutely bunkers compared to just building a dictionary in Python and exporting it.
Edit: They've extracted the library into its own thing called diet-ng
For example, here's a 160LOC one I wrote a while back. [0]
[0] https://git.sr.ht/~shakna/lserver/tree/master/item/template....
I'm not the author of the library (pongo2), but I'm using pongo2-runner to dynamically create config files out of environment variables, with custom logic. Super recommended.
https://stackoverflow.com/questions/56084066/is-there-a-way-...