title: Cheetah with Cherrypy: how to load base templates, and do so automatically on change during development
body: <p>I am working on a cherrypy+cheetah app and would like to improve the development experience.</p>
  
  <p>I have everything working when I manually compile templates beforehand. (Update: This is how things work for production: precompile, don't ship *.tmpl and load templates as regular python modules.) However, during development I'd rather just load the templates every time they are referenced so that I don't need to kill and restart my application. I have a couple of issues I am facing:</p>
  
  <ol>
  <li>If I have templates inheriting from base templates, I get import errors (can't find base templates). I think I had this actually working during my experiments, but unfortunately didn't save it and now I can't make it work.</li>
  <li>Suppose I get 1. working, how do make it so that edits even in base templates get picked up without restart.</li>
  </ol>
  
  <p>Below is my sample application that should demonstrate the problems. The directory structure is as follows:</p>
  
  <pre><code>t.py
  templates/
      base.tmpl
      index.tmpl
  </code></pre>
  
  <p>t.py:</p>
  
  <pre><code>import sys
  
  import cherrypy
  from Cheetah.Template import Template
  
  class T:
      def __init__(self, foo):
          self.foo = foo
  
      @cherrypy.expose
      def index(self):
          return Template(file='templates/index.tmpl',
                          searchList=[{'foo': self.foo}]).respond()
  
  cherrypy.quickstart(T(sys.argv[1]))
  </code></pre>
  
  <p>base.tmpl:</p>
  
  <pre><code>#def body
  This is the body from the base
  #end def
  
  This is the base doc
  </code></pre>
  
  <p>index.tmpl:</p>
  
  <pre><code>#from templates.base import base
  #extends base
  #def body
  $base.body(self)
  This is the extended body
  #end def
  
  This is from index
  </code></pre>
  
  <p>Run it like this:</p>
  
  <pre><code>python t.py Something
  </code></pre>