Answer the question
In order to leave comments, you need to log in
How to write your own templating engine in python?
I recently read a joke that every python developer starts their acquaintance with the web by writing their own templating engine and I realized that I can’t figure out how to write it.
How to parse templates correctly? Regulars? And then suffer with recursive constructions? Write your grammars in some peg? Isn't that too slow?
How to approach caching? I know that many php-templaters translate the template into php-code in /tmp, and from there they actually give it away. How does this apply to python? Or keep everything in mind? Isn't it thick?
Will I win if the template engine is written in Cython? Due to strong typing, you can get a gain in memory. Maybe something else?
And as an additional question. I'm unlikely to use it anywhere, but it would also be interesting to integrate it into Django. Something is not googled, how to replace the django template engine.
Answer the question
In order to leave comments, you need to log in
Look at the implementation in Django and Jinja.
You can use custom templates in Django via TEMPLATE_LOADERS (example https://github.com/yuchant/django-jinja2).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question