problem calling a Python external method in a folder from a DTML method
I've had a few questions on DTML in the past week. This should be my last DTML question for a while for serveral reasones: 1) If I can make this last example work, I'm pretty sure that I can do all that I want or need to do in DTML. Actually, I want to do very little in DTML and quite a bit in Python so I don't think I need too much DTML capability. 2) My experiment DTML application will be working once the issue below is resolved. 3) I plan to take the nudging toward ZPT and start an experiment application in ZPT. Hopefully, I will then be done with DTML. Thanks to Troy Farrell, Chris Withers, and Jonathan I have a problem using Zope 2.7.0. I've tried Zope on both a Linux and Windows PC and have the same problem. I'm working on a DTML method in which I want to call an external method in a folder, 'F'. F is a subdirectory of the directory in which the DTML resides. The method, 'M', is in an external module 'M.py', so the path from the current folder is 'F/M'. My folder has a property, "Sample", with a value of "Sample Text". The method, M, returns a string value, "M method". First I try calling F.M() <p>Calling a method</p> <dtml_var expr="F.M()"> <p>After method call</p> Then I try using the dtml-with tag using F as the object being pushed on the stack. <dtml-with F only> <h2>Sample: <dtml-var sample></h2> <p>Calling a method</p> <dtml_var expr="M()"> <p>After method call</p> </dtml-with> When this DTML method is run, the output looks like: Calling a method After method call Sample: Sample Text Calling a method After method call The sample property renders properly, but not the method output. The output does not include the string returned by method, 'M'. I've experimented with a number of different possibilities, but I can not get method 'M' to run. But I get no error messages either. I've tried wrapping the calls to 'M' in a dtml-try statement, but no exception was raised. When I test my M.py file in the Extension directory, the python file executes as expected. Can anyone give me a suggestion on how to get this method to execute from the DTML when a dtml-call or dtml-var tag is used? Jim Anderson
On Wed, Mar 10, 2004 at 01:03:43AM -0500, Jim Anderson wrote:
I'm working on a DTML method in which I want to call an external method in a folder, 'F'. F is a subdirectory of the directory in which the DTML resides. The method, 'M', is in an external module 'M.py', so the path from the current folder is 'F/M'.
Just to be sure you know this... that is a non-sequitur. The fact that M is an External Method has nothing to do with the path at which you can call it.
My folder has a property, "Sample", with a value of "Sample Text". The method, M, returns a string value, "M method".
Given the remainder of your message, I am suspicious that your method returns anything at all. Did you test the "M" external method directly in the ZMI? see the "Using External Methods" section of this chapter: http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ScriptingZope.stx ? -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's THE MOONLIGHT CHEETO! (random hero from isometric.spaceninja.com)
Paul Winkler wrote: Paul, thanks for the input.
On Wed, Mar 10, 2004 at 01:03:43AM -0500, Jim Anderson wrote:
I'm working on a DTML method in which I want to call an external method in a folder, 'F'. F is a subdirectory of the directory in which the DTML resides. The method, 'M', is in an external module 'M.py', so the path from the current folder is 'F/M'.
Just to be sure you know this... that is a non-sequitur. The fact that M is an External Method has nothing to do with the path at which you can call it.
Maybe this is part of my problem, but it seems like the path to the external method is relevant. Zope must find the external method to run it. Normally, this would be through acquisition, but since the method is in a subdirectory of the DTML method referring to it, I have used the <dtml-with> to push the namespace of folder F on to the namespace stack. Two things confuse me more. First, there is no error message at all. There are a couple of possibilities. With a statement like, <dtml-var expr="F.M()"> maybe Zope does not consider this an external method reference? It seems like it should, but maybe it doesn't. The syntax I used looks identical to syntax that I've see in the Zope Book and Zope Bible. Interestingly, when I remove the external method M, the DTML runs the same, implying the Zope never looked for M to begin with. Second, why does it find 'F.sample' a property of F, but not the external method M in F? Clearly, F is on the namespace stack.
My folder has a property, "Sample", with a value of "Sample Text". The method, M, returns a string value, "M method".
Given the remainder of your message, I am suspicious that your method returns anything at all.
When I run the test tab in the external method, the return value of the method gets rendered by Zope. This is not the problem.
Did you test the "M" external method directly in the ZMI? see the "Using External Methods" section of this chapter: http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ScriptingZope.stx ?
On Wed, Mar 10, 2004 at 11:06:36AM -0500, Jim Anderson wrote:
Maybe this is part of my problem, but it seems like the path to the external method is relevant. Zope must find the external method to run it. Normally, this would be through acquisition, but since the method is in a subdirectory of the DTML method referring to it, I have used the <dtml-with> to push the namespace of folder F on to the namespace stack.
That's fine.
Two things confuse me more.
First, there is no error message at all. There are a couple of possibilities. With a statement like, <dtml-var expr="F.M()"> maybe Zope does not consider this an external method reference?
The type of object is irrelevant to zope. All that this says is "In the object F (whatever that is), get the attribute M (whatever that is) and call it."
It seems like it should, but maybe it doesn't. The syntax I used looks identical to syntax that I've see in the Zope Book and Zope Bible. Interestingly, when I remove the external method M, the DTML runs the same, implying the Zope never looked for M to begin with.
Ahh - good clue, but your interpretation is a bit off. Zope definitely looked for M, but it very likely found something other than what you expect. If this were not the case, you would have got an error that M was not found.
Second, why does it find 'F.sample' a property of F, but not the external method M in F? Clearly, F is on the namespace stack.
Yes, but usually lots of other stuff is on the stack too, and this may be confusing the issue...
My folder has a property, "Sample", with a value of "Sample Text". The method, M, returns a string value, "M method".
Given the remainder of your message, I am suspicious that your method returns anything at all.
When I run the test tab in the external method, the return value of the method gets rendered by Zope. This is not the problem.
OK, that's good to know. That is another strong indication that your DTML is finding the wrong thing named M. What happens if you change your DTML code to this? <dtml-var expr="F.M.getPhysicalPath()"> It should print a tuple containing the path to this M object. e.g. if M lived at /F1/F2/M, it should display this: ('', 'F1', 'F2', 'M') -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's SPACE ZOMBIE DEATH! (random hero from isometric.spaceninja.com)
Paul Winkler wrote:
Ahh - good clue, but your interpretation is a bit off. Zope definitely looked for M, but it very likely found something other than what you expect. If this were not the case, you would have got an error that M was not found.
OK, that's good to know. That is another strong indication that your DTML is finding the wrong thing named M.
These are pretty strong reasosn for using ZPT instead of DTML... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Chris and Paul, Well I start using ZPT yesterday and what a difference. In a few hours I had my experimental web pages working and that includes the time reading about ZPT. The error messages pretty well pointed me to my mistakes. I still have a lot to learn about ZPT, but it looks very promising. Thanks again for your previous advice. As a general policy, I do believe that Zope.org should make a statement that DTML should NOT be used for new web pages and then list exceptions, if any. This would save new users a lot of time and it would reduce the overhead in this mailing list. Jim Chris Withers wrote:
Paul Winkler wrote:
Ahh - good clue, but your interpretation is a bit off. Zope definitely looked for M, but it very likely found something other than what you expect. If this were not the case, you would have got an error that M was not found.
OK, that's good to know. That is another strong indication that your DTML is finding the wrong thing named M.
These are pretty strong reasosn for using ZPT instead of DTML...
Chris
Jim Anderson wrote:
Well I start using ZPT yesterday and what a difference. In a few hours I had my experimental web pages working and that includes the time reading about ZPT. The error messages pretty well pointed me to my mistakes. I still have a lot to learn about ZPT, but it looks very promising. Thanks again for your previous advice.
Cool :-)
As a general policy, I do believe that Zope.org should make a statement that DTML should NOT be used for new web pages and then list exceptions, if any. This would save new users a lot of time and it would reduce the overhead in this mailing list.
Yeah, I agree with you, but for some reason there are still people who think DTML is a viable way to produce templates in Zope :-( Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Jim -- Read the manual on acquisition. I suspect that your external method is not in the acquisition path. I'd suggest an experiment to learn how it all works. Put the external method in the same folder with your DTML method. Does it work? Try puting the external method in the parent folder of the folder in which your DTML method resides. Does it work? Try creating a folder in the parent call it "EM" and put the external method in it, and reference the external method as EM.M. Does that work. Go back to your original folder setup and wrap the call in a <dtml-with /...../methodfolder/F> and reference the external method (in F) as M(). Does that work? On Wed, 10 Mar 2004, Jim Anderson wrote:
I've had a few questions on DTML in the past week. This should be my last DTML question for a while for serveral reasones:
1) If I can make this last example work, I'm pretty sure that I can do all that I want or need to do in DTML. Actually, I want to do very little in DTML and quite a bit in Python so I don't think I need too much DTML capability. 2) My experiment DTML application will be working once the issue below is resolved. 3) I plan to take the nudging toward ZPT and start an experiment application in ZPT. Hopefully, I will then be done with DTML.
Thanks to Troy Farrell, Chris Withers, and Jonathan
I have a problem using Zope 2.7.0. I've tried Zope on both a Linux and Windows PC and have the same problem.
I'm working on a DTML method in which I want to call an external method in a folder, 'F'. F is a subdirectory of the directory in which the DTML resides. The method, 'M', is in an external module 'M.py', so the path from the current folder is 'F/M'. My folder has a property, "Sample", with a value of "Sample Text". The method, M, returns a string value, "M method".
First I try calling F.M() <p>Calling a method</p> <dtml_var expr="F.M()"> <p>After method call</p>
Then I try using the dtml-with tag using F as the object being pushed on the stack.
<dtml-with F only> <h2>Sample: <dtml-var sample></h2>
<p>Calling a method</p> <dtml_var expr="M()"> <p>After method call</p> </dtml-with>
When this DTML method is run, the output looks like:
Calling a method
After method call
Sample: Sample Text
Calling a method
After method call
The sample property renders properly, but not the method output. The output does not include the string returned by method, 'M'. I've experimented with a number of different possibilities, but I can not get method 'M' to run. But I get no error messages either. I've tried wrapping the calls to 'M' in a dtml-try statement, but no exception was raised.
When I test my M.py file in the Extension directory, the python file executes as expected.
Can anyone give me a suggestion on how to get this method to execute from the DTML when a dtml-call or dtml-var tag is used?
Jim Anderson
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Dennis Allison wrote: Dennis, I'm still having troubles. I'll review the acquisition information and see if I've missed something.
Jim -- Read the manual on acquisition. I suspect that your external method is not in the acquisition path.
Part of my experiment was to use the <dtml-with F> to push the folder F on to the namespace stack. Method M is in F and if I understand correctly, then zope should find properties and methods in F. It does find the property on F, but not the method :(
I'd suggest an experiment to learn how it all works. Put the external method in the same folder with your DTML method. Does it work?
I tried putting M in the same folder as the DTML method. This did not work either.
Try puting the external method in the parent folder of the folder in which your DTML method resides.Does
it work?
No luck here either.
Try creating a folder in the parent call it "EM" and
put the external method in it, and reference the external method as EM.M. Does that work.
Again, it does not work.
Go back to your original folder setup and wrap the call in a <dtml-with /...../methodfolder/F> and reference the external method (in F) as M(). Does that work?
Zope did not like see slashes in the <dtml-with> statement. But at least I got an error message here.
On Wed, 10 Mar 2004, Jim Anderson wrote:
I've had a few questions on DTML in the past week. This should be my last DTML question for a while for serveral reasones:
1) If I can make this last example work, I'm pretty sure that I can do all that I want or need to do in DTML. Actually, I want to do very little in DTML and quite a bit in Python so I don't think I need too much DTML capability. 2) My experiment DTML application will be working once the issue below is resolved. 3) I plan to take the nudging toward ZPT and start an experiment application in ZPT. Hopefully, I will then be done with DTML.
Thanks to Troy Farrell, Chris Withers, and Jonathan
I have a problem using Zope 2.7.0. I've tried Zope on both a Linux and Windows PC and have the same problem.
I'm working on a DTML method in which I want to call an external method in a folder, 'F'. F is a subdirectory of the directory in which the DTML resides. The method, 'M', is in an external module 'M.py', so the path from the current folder is 'F/M'. My folder has a property, "Sample", with a value of "Sample Text". The method, M, returns a string value, "M method".
First I try calling F.M() <p>Calling a method</p> <dtml_var expr="F.M()"> <p>After method call</p>
Then I try using the dtml-with tag using F as the object being pushed on the stack.
<dtml-with F only> <h2>Sample: <dtml-var sample></h2>
<p>Calling a method</p> <dtml_var expr="M()"> <p>After method call</p> </dtml-with>
When this DTML method is run, the output looks like:
Calling a method
After method call
Sample: Sample Text
Calling a method
After method call
The sample property renders properly, but not the method output. The output does not include the string returned by method, 'M'. I've experimented with a number of different possibilities, but I can not get method 'M' to run. But I get no error messages either. I've tried wrapping the calls to 'M' in a dtml-try statement, but no exception was raised.
When I test my M.py file in the Extension directory, the python file executes as expected.
Can anyone give me a suggestion on how to get this method to execute from the DTML when a dtml-call or dtml-var tag is used?
Jim Anderson
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Jim Anderson wrote:
of the directory in which the DTML resides. The method, 'M', is in an external module 'M.py', so the path from
The code from M.py would be handy. Can it returtn a blank string in any circumstances? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Chris Withers wrote:
Jim Anderson wrote:
of the directory in which the DTML resides. The method, 'M', is in an external module 'M.py', so the path from
The code from M.py would be handy. Can it returtn a blank string in any circumstances?
cheers,
Chris
Chris, No, it always returns a string. M.py is as follows: def M(): return("M module") Jim
participants (4)
-
Chris Withers -
Dennis Allison -
Jim Anderson -
Paul Winkler