Reputation: 29727
I am trying to setup dynamic compilation of Cheetah templates, useful for development (so I don't have to recompile them with cheetah compile
after each change). Seems like Cheetah.Template.Template
is right API for that, but it simply doesn't handle parent templates.
So if I have:
-- __init__.py
-- index.tmpl:
#extends layout.A
-- layout/
-- __init__.py
-- A.tmpl:
#echo 'Hello!'
If I run Python in root directory, I'd get the next:
>>> from Cheetah.Template import Template; t = Template(file='index.tmpl')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/Cheetah-2.4.3-py2.6-freebsd-7-amd64.egg/Cheetah/Template.py", line 1259, in __init__
self._compile(source, file, compilerSettings=compilerSettings)
...
ImportError: No module named A
If I compile A.tmpl
with cheetah compile
, error disappears, but changes in template doesn't affect result of index.tmpl
compilation:
$ cat layout/A.tmpl
#echo 'Hello, world!'
$ python
>>> from Cheetah.Template import Template; t = Template(file='index.tmpl')
>>> str(t)
'Hello!'
Should I recompile all parent templates by myself (e.g. like Aquarium
framework does)?
Cheetah version 2.4.
Any tips about Django1.3\Cheetah integration are also appreciated.
Upvotes: 3
Views: 372
Reputation: 340
Some where early in your process startup, include the following two lines:
import Cheetah.ImportHooks
Cheetah.ImportHooks.install()
I believe this will give you the behavior you are looking for.
This is not documented in the main docs, but Tavis Rudd suggested this in response to a similar question on the Cheetah mailing list.
Upvotes: 2