将参数传递给 Zope 浏览器页面
在我的 Zope 实例中,我有一个 Python 脚本注册为浏览器页面。我有以下代码作为其注册表:
这个函数“PyTest.CallPy”定义为:
def CallPy(self, data): ...
然后我使用 JavaScript 调用该函数,传递数据:
$.ajax({ url: "@@test", data: ({data: "mydata"}), dataType: "text", 成功: ..., 错误: ... });
但是,当我进行此调用时,我收到一条错误消息“CallPy() 仅需要 2 个参数(给定 1 个参数)”。
如何将此函数注册为在调用时传递此数据的页面?
In my Zope instance, I have a Python script registered as a browser page. I have the following code as its registry:
<browser:page name="test" for="*" permission="zope2.Public" class="browser.test.PyTest" attribute="CallPy" />
This function, "PyTest.CallPy" is defined as:
def CallPy(self, data): ...
I then use JavaScript to call the function, passing data in:
$.ajax({ url: "@@test", data: ({data: "mydata"}), dataType: "text", success: ..., error: ... });
However, when I make this call, I get an error that says "CallPy() takes exactly 2 arguments (1 given)".
How do I register this function as a page that passes in this data when it is called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少有关您的方法的很多细节。它是一个类的方法吗?还是独立的?通常,self 会引用 PyTest 类的实例 - 它是 BrowserView 的子类。
然后,从 Request 对象中检索您传递给视图 (@@test) 的数据,该对象在 self.request 中可用(具体来说,在本例中,self.request.form.data)(因此,您无需为该方法指定“数据”参数)。
嗯。我认为您不希望在
data: ({data: "mydata"})
中的字典两边加上括号。You're missing rather a lot of detail on your method. Is it a method of a class? Or standalone? Normally, self would refer to an instance of the class PyTest - which would be a subclass of BrowserView.
Then, the data you pass to the view (@@test) is retrieved from the Request object, which is available in self.request (specifically, in this case, self.request.form.data) (So, you don't specify a 'data' argument to the method).
hmmm. I don't think you want the parentheses around the dict in:
data: ({data: "mydata"})
.