Plone 外部方法帮助

0 投票
3 回答
1277 浏览
提问于 2025-04-16 00:38

我在使用Plone时遇到了一些麻烦,想让一个简单的外部方法正常工作。在我的扩展文件夹里,有一个叫做blast_query.py的Python脚本,代码如下:

def print_query(self, x):
    print(x)

我的外部方法看起来是这样的:

编号:run_blast_query

标题:

模块名称:blast_query

函数名称:print_query

在ZMI中,我的Python脚本是这样的:

#Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE = request.RESPONSE

# Insert data that was passed from the form
query=request.query

context.print_query(context,query)

我只是想把表单中的查询传递给这个函数,这样我就能确认它是否正常工作。

有什么建议吗?

3 个回答

0

"request"可以通过"self"来获取。

在你的外部方法中使用self.REQUEST。

不需要额外的参数。

0

这是你对Python方法理解上的一个问题。

我本来期待:

context.print_query(context,query)

会返回:

TypeError: print_query() takes exactly 2 arguments (3 given)

记住,在Python中,obj.method() 会自动把 obj 作为 method() 的第一个参数传进去。

1

你应该通过ID来调用你的外部方法:

context.run_blast_query(context,query)

撰写回答