I want using a different templating language with Django. It’s actually HamlPy, which is a HAML-inspired language, that directly translates to Django templates.
Thus, I can do something like
from hamlpy import Compiler
compiler = Compiler()
django_template_string = compiler.process(hamlpy_template_string)
Please notice, it doesn’t need any context – it’s just template text preprocessing. The resultant text can than be used as a Django template in a normal way.
So, I want to wrap this code inside some deus-ex-machina code that will gracefully intervent template loading and preprocess it before Django tries to render or even parse it.
From what I see, if I could overload the Parser class and do
def parse(str):
str = preprocess(str)
super().parse(str)
it would be the most transparent solution.
I know about custom tags and filters. I realize that my task can be solved with the “global” `preprocess_hamlpy’ tag.
But I wonder if it can be done in a different way.
Write a template loader and put it in your settings.