Re: [Cheetahtemplate-discuss] can't fill templates from strings
Brought to you by:
rtyler,
tavis_rudd
From: Doug W. <do...@so...> - 2004-07-07 02:57:40
|
Hi Aaron, Thanks for the reply. Your example works fine. I must be misunderstanding something about using inheritence in my templates because the problem only manifests with them. I'll try to boil this down to a small test case if necessary, but before I do that, here are what seem like the relevant bits: source text: #extends sonosphere sonosphere.tmpl: #extends basepage basepage.tmpl: #extends rootpage #implements respond rootpage.py: class rootpage(Template): These are all in the same directory. Is the "#implements respond" necessary in templates which inherit from basepage? Also, I have no idea why, but this fixes the problem if I invoke it before my templates: import tempfile if tempfile.tempdir == None and tempfile.gettempdir() == '/tmp' and sys.platform == 'darwin': tempfile.tempdir = '/private/tmp' I'm running in a CGI context if that matters, but my web server is on localhost and runs as me, not "nobody" or "www". Also, I'm inserting my template directory at the front of sys.path. Thanks Doug On Jul 6, 2004, at 12:20, Aaron Held wrote: > Can you post the code? > > I do this all the time: > > templateDef='''\ > Hello $rf''' > rf = 'Aaron' > t = Template(templateDef,[{'rf':rf}]) > > Doug Wyatt wrote: > >> Hi, >> >> I'm using Cheetah 0.9.15 on Mac OS X 10.3. >> >> I can compile and fill templates from files just fine. I changed my >> code so that I was creating a template from a string, however, and >> this fails: >> >> Traceback (most recent call last): >> ... >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Template.py", line 156, in __init__ >> self.compile(source, file) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Template.py", line 245, in compile >> compiler.compile() >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Compiler.py", line 1086, in compile >> self.parse() >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Parser.py", line 1036, in parse >> self.eatDirective() >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Parser.py", line 1150, in >> eatDirective >> self.directiveEaters[directiveKey]() >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Parser.py", line 1470, in eatExtends >> mod = >> self._templateObj._importAsDummyModule('\n'.join(self._importStatement >> s) ) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Template.py", line 453, in >> _importAsDummyModule >> packageName = self._makeDummyPackageForDir(moduleDir) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Template.py", line 477, in >> _makeDummyPackageForDir >> isPackageDir=1,forceReload=1) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ >> python2.3/site-packages/Cheetah/Template.py", line 529, in >> _importModuleFromDirectory >> fp, pathname, stuff = imp.find_module(moduleName, [directory]) >> ImportError: No module named tmp >> >> In _importModuleFromDirectory: >> fullModuleName= Cheetah.Temp._tmp >> moduleName= tmp >> directory= / >> >> So I guess Python is not finding the "__init__.py" written into /tmp. >> >> I wonder if it's because on Mac OS X, /tmp is a symlink to >> /private/tmp ? >> >> Would appreciate any help. >> >> Thanks >> Doug >> >> >> >> ------------------------------------------------------- >> This SF.Net email sponsored by Black Hat Briefings & Training. >> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital >> self defense, top technical experts, no vendor pitches, unmatched >> networking opportunities. Visit www.blackhat.com >> _______________________________________________ >> Cheetahtemplate-discuss mailing list >> Che...@li... >> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss > > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital > self defense, top technical experts, no vendor pitches, unmatched > networking opportunities. Visit www.blackhat.com > _______________________________________________ > Cheetahtemplate-discuss mailing list > Che...@li... > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss > > |