[Zope] what the namespace means in Script(python)?
Litao Wei
wlt008 at gmail.com
Wed Jul 27 13:45:32 EDT 2005
Hi list:
In Script(python) binding page. there is some description about
namespace binding:
When the script is called from DTML, this is the caller's DTML
namespace, otherwise it is an empty namespace.
Recommended value: |_| (underscore character)
But in zope book, when talk about Error Handling in the Advanced Page
Templates chapter. It looks that it use ZPT with script's namespace. See
below.
For more flexible error handling you can call a script. For example:
<div tal:on-error="structure here/handleError">
...
</div>
Any error that occurs inside the |div| will call the |handleError|
script. Note that the |structure| option allows the script to return
HTML. Your error handling script can examine the error and take various
actions depending on the error. Your script gets access to the error
through the |error| variable in the namespace. For example:
## Script (Python) "handleError"
##bind namespace=_
##
error=_['error']
if error.type==ZeroDivisionError:
return "<p>Can't divide by zero.</p>"
else:
return """<p>An error occurred.</p>
<p>Error type: %s</p>
<p>Error value: %s</p>""" % (error.type,
error.value)
So what happened with namespace when calling Script from ZPT?
More information about the Zope
mailing list