[ZPT] AttributeError using METAL outside of Zope

Francis Barnhart franimal@speakeasy.net
Tue, 3 Dec 2002 12:08:17 -0800


Hi,

Using PageTemplates 1.5 with Python 2.2.2 I get an AttributeError on the id of the macro. Below is an interactive session based on an earlier posting to this list. (Note: the PageTemplate class _is_ subclassed from Base, so this seems to be a different problem). Thanks.

Francis

>>> pt = PageTemplate()
>>> template_file = open('d:/website/page.html')
>>> pt.write(template_file.read())
>>> template_file.close()
>>> pt.read()
'<html metal:use-macro="options/standard_page/macros/master">\n\t<div metal:fill-slot="main">\n\t\t<p><b>Inner Page</b></p>\n\t</div>\n</html>\n'
>>> standard_page = PageTemplate()
>>> template_file = open('d:/website/standard_page.html')
>>> standard_page.write(template_file.read())
>>> template_file.close()
>>> standard_page.read()
'<html metal:define-macro="master">\n\t<p>Outer page</p>\n\n\t<div metal:define-slot="main">\n\t</div>\n</html>\n'
>>> pt(standard_page=standard_page)
Traceback (most recent call last):
  File "<pyshell#27>", line 1, in ?
    pt(standard_page=standard_page)
  File "C:\Python22\lib\site-packages\PageTemplates\PageTemplate.py", line 97, in __call__
    return self.pt_render(extra_context={'options': kwargs})
  File "C:\Python22\lib\site-packages\PageTemplates\PageTemplate.py", line 91, in pt_render
    tal=not source, strictinsert=0)()
  File "C:\Python22\lib\site-packages\TAL\TALInterpreter.py", line 159, in __call__
    self.interpret(self.program)
  File "C:\Python22\lib\site-packages\TAL\TALInterpreter.py", line 192, in interpret
    handlers[opcode](self, args)
  File "C:\Python22\lib\site-packages\TAL\TALInterpreter.py", line 516, in do_useMacro
    macro = self.engine.evaluateMacro(macroExpr)
  File "C:\Python22\lib\site-packages\PageTemplates\TALES.py", line 217, in evaluate
    v = expression(self)
  File "C:\Python22\lib\site-packages\PageTemplates\Expressions.py", line 192, in __call__
    return self._eval(econtext)
  File "C:\Python22\lib\site-packages\PageTemplates\Expressions.py", line 182, in _eval
    ob = self._subexprs[-1](econtext)
  File "C:\Python22\lib\site-packages\PageTemplates\Expressions.py", line 141, in _eval
    ob = restrictedTraverse(ob, path, getSecurityManager())
  File "C:\Python22\lib\site-packages\PageTemplates\Expressions.py", line 356, in restrictedTraverse
    get(object, name)
AttributeError: master