Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] #include directive and search paths

Expand Messages
  • Maciej BliziƄski
    I have a question about using the #include directive. For example, the following example works as expected: echo foo foo.tmpl echo #include foo.tmpl
    Message 1 of 1 , Apr 22, 2011
    • 0 Attachment
      I have a question about using the #include directive. For example,
      the following example works as expected:

      echo "foo" > foo.tmpl
      echo "#include \"foo.tmpl\"" > bar.tmpl
      python -c "from Cheetah.Template import Template; \
      t = Template(file='bar.tmpl'); \
      print unicode(t)"

      However, if the template files are moved to a subdirectory, an
      exception is thrown:

      mkdir -p subdir
      mv *.tmpl subdir
      python -c "from Cheetah.Template import Template; \
      t = Template(file='subdir/bar.tmpl'); \
      print unicode(t)"

      Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/pymodules/python2.6/Cheetah/Template.py", line 981, in __str__
      def __str__(self): return getattr(self, mainMethName)()
      File "_home_maciej_src_cheetah_test_subdir_bar_tmpl.py", line 86, in respond
      File "/usr/lib/pymodules/python2.6/Cheetah/Template.py", line 1511,
      in _handleCheetahInclude
      nestedTemplateClass = compiler.compile(source=source,file=file)
      File "/usr/lib/pymodules/python2.6/Cheetah/Template.py", line 692, in compile
      fileHash = str(hash(file))+str(os.path.getmtime(file))
      File "/usr/lib/python2.6/genericpath.py", line 54, in getmtime
      return os.stat(filename).st_mtime
      OSError: [Errno 2] No such file or directory:

      It looks like Cheetah looks for the template to include in the
      process' cwd, instead of the directory containing the original
      template. If the template were created from a string or a unicode
      object, that would understandable. But Cheetah does know the path to
      the template ("subdir") and it's reasonable to assume that this is the
      place to look for other templates too.

      If there a workaround for this problem?


      Fulfilling the Lean Software Promise
      Lean software platforms are now widely adopted and the benefits have been
      demonstrated beyond question. Learn why your peers are replacing JEE
      containers with lightweight application servers - and what you can gain
      from the move. http://p.sf.net/sfu/vmware-sfemails
      Cheetahtemplate-discuss mailing list
    Your message has been successfully submitted and would be delivered to recipients shortly.