[Zope-CMF] problems rendering ZPT in Python Script
Grégoire Weber
gregoire.weber@switzerland.org
Mon, 13 May 2002 16:33:39 +0200
Hi,
I wanted to return a rendered ZPT by a Python Script. The result was a
bit confusing to me. The skin folder contains a Python Script named
'topic_view' and a ZPT named 'topic_view_body_anon'.
I searched the mailing list and the http://www.zopelabs.com but didn't
find a answer.
I get an error if I do:
obj = getattr(container, '%s%s' % (context.template_name, '_anon'))
html = obj()
an no error (thus the rendered page) if I do:
obj = context.topic_view_body_anon
html = obj()
What is confusing me is that both 'obj' reference the same object
(e.g. <ZopePageTemplate instance at 01701898>).
What's going on?
Any pointers?
Thanks, Greg
------------------------------- python script
print '<pre>'
obj = getattr(container, '%s%s' % (context.template_name, '_anon'))
print 'obj: %s' % obj
print 'obj.getId(): %s' % obj.getId()
try:
html = 'obj(): %s' % obj()
print 'obj(): OK'
except:
print 'obj(): ERROR'
print 'context.topic_view_body_anon: %s' % context.topic_view_body_anon
print 'context.topic_view_body_anon.getId(): %s' % context.topic_view_body_anon.getId()
obj = context.topic_view_body_anon
try:
html = 'context.topic_view_body_anon(): %s' % obj()
print 'context.topic_view_body_anon(): OK'
except:
print 'context.topic_view_body_anon(): ERROR'
print '</pre>'
return printed
----------------------------- result of script
<pre>
obj: <ZopePageTemplate instance at 01701898>
obj.getId(): topic_view_body_anon
obj(): ERROR
context.topic_view_body_anon: <ZopePageTemplate instance at 01701898>
context.topic_view_body_anon.getId(): topic_view_body_anon
context.topic_view_body_anon(): OK
</pre>
----------------------------- error message
Site Error
An error was encountered while publishing this resource.
Error Type: TALESError
Error Value: exceptions.AttributeError on queryCatalog in "", at line 15, column 3
Troubleshooting Suggestions
The URL may be incorrect.
The parameters passed to this resource may be incorrect.
A resource that this resource relies on may be encountering an error.
For more detailed information about the error, please refer to the HTML source for this page.
If the error persists please contact the site maintainer. Thank you for your patience.
Traceback (innermost last):
File D:\prog\zope_25x\lib\python\ZPublisher\Publish.py, line 150, in publish_module
File D:\prog\zope_25x\lib\python\ZPublisher\Publish.py, line 114, in publish
File D:\prog\zope_25x\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook
(Object: home)
File D:\prog\zope_25x\lib\python\ZPublisher\Publish.py, line 98, in publish
File D:\prog\zope_25x\lib\python\ZPublisher\mapply.py, line 88, in mapply
(Object: gaga)
File D:\prog\zope_25x\lib\python\ZPublisher\Publish.py, line 39, in call_object
(Object: gaga)
File D:\prog\zope_25x\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in __call__
(Object: gaga)
File D:\prog\zope_25x\lib\python\Shared\DC\Scripts\Bindings.py, line 283, in _bindAndExec
(Object: gaga)
File D:\prog\zope_25x\lib\python\Products\PythonScripts\PythonScript.py, line 302, in _exec
(Object: gaga)
(Info: ({'script': <PythonScript instance at 02C5B388>, 'context': <Topic instance at 017796B8>, 'container': <CMFSite instance at 015D1548>, 'traverse_subpath': []}, (), {}, None))
File Script (Python), line 6, in gaga
File D:\prog\zope_25x\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in __call__
(Object: topic_view_body_anon)
File D:\prog\zope_25x\lib\python\Shared\DC\Scripts\Bindings.py, line 283, in _bindAndExec
(Object: topic_view_body_anon)
File D:\prog\zope_25x\lib\python\Products\PageTemplates\ZopePageTemplate.py, line 210, in _exec
(Object: topic_view_body_anon)
File D:\prog\zope_25x\lib\python\Products\PageTemplates\PageTemplate.py, line 86, in pt_render
(Object: topic_view_body_anon)
(Info: {'container': <CMFSite instance at 015D1548>,
'here': <CMFSite instance at 015D1548>,
'modules': <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 00F7AD1C>,
'nothing': None,
'options': {'args': ()},
'request': <h3>form</h3><table></table><h3>cookies</h3><table><tr valign="top" align="left"><th>__ac_name</th><td>'gregweb'</td></tr><tr valign="top" align="left"><th>dtpref_cols</th><td>'90'</td></tr><tr valign="top" align="left"><th>dtpref_rows</th><td>'25'</td></tr></table><h3>lazy items</h3><table><tr valign="top" align="left"><th>SESSION</th><td><Python Method object at 015CB6C8></td></tr></table><h3>other</h3><table><tr valign="top" align="left"><th>AUTHENTICATION_PATH</th><td>''</td></tr><tr valign="top" align="left"><th>URL1</th><td>'http://localhost/incept/home'</td></tr><tr valign="top" align="left"><th>dtpref_rows</th><td>'25'</td></tr><tr valign="top" align="left"><th>BASE3</th><td>'http://localhost/incept/home'</td></tr><tr valign="top" align="left"><th>PUBLISHED</th><td><PythonScript instance at 02C5B388></td></tr><tr valign="top" align="left"><th>URL3</th><td>'http://localhost'</td></tr><tr valign="top" align="left"><th>__ac_name</th><td>'gregweb'</td></tr><tr valign="top" align="left"><th>BASE0</th><td>'http://localhost'</td></tr><tr valign="top" align="left"><th>URL2</th><td>'http://localhost/incept'</td></tr><tr valign="top" align="left"><th>BASE1</th><td>'http://localhost'</td></tr><tr valign="top" align="left"><th>traverse_subpath</th><td>[]</td></tr><tr valign="top" align="left"><th>URL0</th><td>'http://localhost/incept/home/gaga'</td></tr><tr valign="top" align="left"><th>SERVER_URL</th><td>'http://localhost'</td></tr><tr valign="top" align="left"><th>BASE4</th><td>'http://localhost/incept/home/gaga'</td></tr><tr valign="top" align="left"><th>URL</th><td>'http://localhost/incept/home/gaga'</td></tr><tr valign="top" align="left"><th>AUTHENTICATED_USER</th><td>Anonymous=
User</td></tr><tr valign="top" align="left"><th>BASE2</th><td>'http://localhost/incept'</td></tr><tr valign="top" align="left"><th>TraversalRequestNameStack</th><td>[]</td></tr><tr valign="top" align="left"><th>dtpref_cols</th><td>'90'</td></tr><tr valign="top" align="left"><th>URL0</th><td>http://localhost/incept/home/gaga</td></tr><tr valign="top" align="left"><th>URL1</th><td>http://localhost/incept/home</td></tr><tr valign="top" align="left"><th>URL2</th><td>http://localhost/incept</td></tr><tr valign="top" align="left"><th>URL3</th><td>http://localhost</td></tr><tr valign="top" align="left"><th>BASE0</th><td>http://localhost</td></tr><tr valign="top" align="left"><th>BASE1</th><td>http://localhost</td></tr><tr valign="top" align="left"><th>BASE2</th><td>http://localhost/incept</td></tr><tr valign="top" align="left"><th>BASE3</th><td>http://localhost/incept/home</td></tr><tr valign="top" align="left"><th>BASE4</th><td>http://localhost/incept/home/gaga</td></tr></table><h3>environ</h3><table><tr valign="top"=
align="left"><th>HTTP_ACCEPT_ENCODING</th><td>'gzip'</td></tr><tr valign="top" align="left"><th>channel.creation_time</th><td>1021299295</td></tr><tr valign="top" align="left"><th>SERVER_PROTOCOL</th><td>'HTTP/1.0'</td></tr><tr valign="top" align="left"><th>SERVER_PORT</th><td>'80'</td></tr><tr valign="top" align="left"><th>PATH_INFO</th><td>'/incept/home/gaga'</td></tr><tr valign="top" align="left"><th>HTTP_HOST</th><td>'localhost'</td></tr><tr valign="top" align="left"><th>REQUEST_METHOD</th><td>'GET'</td></tr><tr valign="top" align="left"><th>PATH_TRANSLATED</th><td>'\\incept\\home\\gaga'</td></tr><tr valign="top" align="left"><th>CONNECTION_TYPE</th><td>'Keep-Alive'</td></tr><tr valign="top" align="left"><th>SCRIPT_NAME</th><td>''</td></tr><tr valign="top" align="left"><th>SERVER_SOFTWARE</th><td>'Zope/(Zope 2.5.1 (binary release, python 2.1, win32-x86), python 2.1.3, win32) ZServer/1.1b1'</td></tr><tr valign="top" align="left"><th>HTTP_ACCEPT_LANGUAGE</th><td>'de-CH,en'</td></tr><tr valign="top" align="left"><th>REMOTE_ADDR</th><td>'127.0.0.1'</td></tr><tr valign="top" align="left"><th>HTTP_COOKIE</th><td>'dtpref_rows="25"; dtpref_cols="90"; __ac_name="gregweb"'</td></tr><tr valign="top" align="left"><th>SERVER_NAME</th><td>'frankl'</td></tr><tr valign="top" align="left"><th>GATEWAY_INTERFACE</th><td>'CGI/1.1'</td></tr><tr valign="top" align="left"><th>HTTP_USER_AGENT</th><td>'Mozilla/4.79 [en] (Windows NT 5.0; U)'</td></tr><tr valign="top" align="left"><th>HTTP_ACCEPT_CHARSET</th><td>'iso-8859-1,*,utf-8'</td></tr><tr valign="top" align="left"><th>HTTP_ACCEPT</th><td>'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*'</td></tr></table>,
'root': <Application instance at 01654C58>,
'template': <ZopePageTemplate instance at 017802E8>,
'traverse_subpath': [],
'user': Anonymous User})
File D:\prog\zope_25x\lib\python\TAL\TALInterpreter.py, line 158, in __call__
File D:\prog\zope_25x\lib\python\TAL\TALInterpreter.py, line 191, in interpret
File D:\prog\zope_25x\lib\python\TAL\TALInterpreter.py, line 523, in do_useMacro
File D:\prog\zope_25x\lib\python\TAL\TALInterpreter.py, line 191, in interpret
File D:\prog\zope_25x\lib\python\TAL\TALInterpreter.py, line 542, in do_defineSlot
File D:\prog\zope_25x\lib\python\TAL\TALInterpreter.py, line 191, in interpret
File D:\prog\zope_25x\lib\python\TAL\TALInterpreter.py, line 402, in do_setLocal_tal
File D:\prog\zope_25x\lib\python\Products\PageTemplates\TALES.py, line 247, in evaluate
File D:\prog\zope_25x\lib\python\Products\PageTemplates\ZRPythonExpr.py, line 49, in __call__
(Info: here.queryCatalog(sort_on='Date', sort_order='descending'))
File Python expression "here.queryCatalog(sort_on='Date', sort_order='descending')", line 2, in f
File D:\prog\zope_25x\lib\python\AccessControl\ZopeGuards.py, line 47, in guarded_getattr
(Object: incept)
TALESError: (see above)
_____________________________________
Grégoire Weber
mailto:gregoire.weber@switzerland.org