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?
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"}).