Zope中的Python脚本在外部方法中找不到函数名

Jan*_*kie 2 python zope plone dtml

我在Plone中获取Python脚本以查找外部方法时遇到问题.鉴于三个不同的对象:

  1. 称为CloneList(Id和函数名称)的外部方法
  2. 使用此成功引用它的DTML文档

    <dtml-var "CloneList(PAGE,ORG,STATUS,CGAP_DATA_HOME,BASE)">
    
    Run Code Online (Sandbox Code Playgroud)
  3. 一个Python脚本,通过这个引用外部方法......

    return CloneList(PAGE,ORG,STATUS,CGAP_DATA_HOME,BASE)
    
    Run Code Online (Sandbox Code Playgroud)

DTML文档工作正常但Python脚本由于某种原因抛出:

Error Value: global name 'CloneList' is not defined
Run Code Online (Sandbox Code Playgroud)

为什么DTML模板可以看到CloneList,但Python脚本不能?

Mar*_*ers 5

DTML命名空间包含当前上下文,而Python Script命名空间则不包含.Python代码必须使用显式方法来引用脚本之外的其他对象.

您可以使用该context对象引用ZODB中的其他对象,如外部方法:

return context.CloneList(PAGE, ORG, STATUS, CGAP_DATA_HOME, BASE)
Run Code Online (Sandbox Code Playgroud)

你也可以查找名字container; 其中,context使用采集链中寻找名字,container只着眼于脚本住在该文件夹,以及所有父文件夹.