calling DTMLFile from an External Method
How do I make use of DTMLFile from an External Method? No matter what I try, I can't get it to work. I think I'm now close, but can't get past this latest problem: Here's my External Method: ---- from Globals import InitializeClass, DTMLFile, package_home from Acquisition import Implicit from Globals import Persistent from DocumentTemplate import HTML def tst1(): stuff = DTMLFile('Extensions/sample', globals()) results = stuff() return results ---- Here's the snippet of a DTML Method that invokes it: <dtml-let ans="tst1()"> <dtml-var ans><br> </dtml-let> ---- But when I 'View' or otherwise invoke the DTML Method, I get Error Type: KeyError Error Value: __name__ I've looked back through the archives, but can't find an answer to this problem. What's wrong with my External Method and what do I need to add to get the DTMLFile call to work? -- Tim Lynch tim.lynch@cornell.edu Information Technology Section 607.255.9570 Albert R. Mann Library Cornell University Ithaca, NY 14853
Tim Lynch wrote:
How do I make use of DTMLFile from an External Method?
No matter what I try, I can't get it to work. I think I'm now close, but can't get past this latest problem:
Here's my External Method:
---- from Globals import InitializeClass, DTMLFile, package_home from Acquisition import Implicit from Globals import Persistent from DocumentTemplate import HTML
def tst1():
stuff = DTMLFile('Extensions/sample', globals()) results = stuff()
return results
<untested> First define the dml method "sample" somewhere in Zope. Ie. in the same folder as your external method: And then put something like this in the external method: def tst1(self): return self.sample(None, self) </untested> regards Max M
Tim Lynch wrote:
How do I make use of DTMLFile from an External Method?
No matter what I try, I can't get it to work. I think I'm now close, but can't get past this latest problem:
Here's my External Method:
---- from Globals import InitializeClass, DTMLFile, package_home from Acquisition import Implicit from Globals import Persistent from DocumentTemplate import HTML
def tst1():
stuff = DTMLFile('Extensions/sample', globals()) results = stuff()
results = self.stuff( REQUEST )
return results
---- Here's the snippet of a DTML Method that invokes it:
<dtml-let ans="tst1()"> <dtml-var ans><br> </dtml-let>
---- But when I 'View' or otherwise invoke the DTML Method, I get
Error Type: KeyError Error Value: __name__
I've looked back through the archives, but can't find an answer to this problem.
What's wrong with my External Method and what do I need to add to get the DTMLFile call to work?
[Tim Lynch]
How do I make use of DTMLFile from an External Method?
No matter what I try, I can't get it to work. I think I'm now close, but can't get past this latest problem:
Even after you find out how, I urge you not to do it. Instead, write some more Python code in your external method to do the processing you want to do. Then return the result to a dtml method or document to be rendered for display. If you need to pass some data from a dtml method to the external method, pass it as a parameter when you call the external method. Alternatively, have your dtml method call the external method, get the results, and then continue to process them with dtml. Work hard to maintain a clean separation between the External Method code and dtml. Your code will be much easier to understand and maintain. Cheers, Tom P
participants (4)
-
hans -
Max M -
Thomas B. Passin -
Tim Lynch