Hello everyone, I want to get a value from a form on one page to either a dtml-in variable or dtml-unless variable on another page, which I seem to be able to do, but for some reason I get no iteration. I'm able to send the variable over to the other page just fine, but neither the dtml-in nor the dtml-unless wants to do their thing. I'm using the Database connection examples from the Zope Book as my examples, but I'm clearly not doing something right... On the page where I get my value from a form is this: <form action="result-test" method="POST"> <input type="text" name="iterations:int"> <input type="submit" value="submit"> and on the page I'm going to, I have this: <dtml-in iterations> This is a test </dtml-in> So, when I test, this is the error I get. I don't know what it means, though... Error Type: TypeError Error Value: len() of unsized object How do I fix this? Thanks! Russell
Russell Hires wrote:
Hello everyone,
I want to get a value from a form on one page to either a dtml-in variable or dtml-unless variable on another page, which I seem to be able to do, but for some reason I get no iteration. I'm able to send the variable over to the other page just fine, but neither the dtml-in nor the dtml-unless wants to do their thing. I'm using the Database connection examples from the Zope Book as my examples, but I'm clearly not doing something right...
On the page where I get my value from a form is this: <form action="result-test" method="POST"> <input type="text" name="iterations:int"> <input type="submit" value="submit">
and on the page I'm going to, I have this: <dtml-in iterations> This is a test </dtml-in> So, when I test, this is the error I get. I don't know what it means, though... Error Type: TypeError Error Value: len() of unsized object
How do I fix this?
Hi, Russell <dtml-in> operates on list-ish things, which means it barfs on integers like your variable "iterations". Fortunately, python to the rescue: "_.range(iterations)" makes a list-ish thing with "iterations" number of things from zero to "iterations -1". Look in any python reference for range() if you need more, and check the zope docs, too because _.range() is limited in zope for a fairly obvious reason. home, home on the range() -- Jim Washington
Hi, Russell
<dtml-in> operates on list-ish things, which means it barfs on integers like your variable "iterations". Fortunately, python to the rescue: "_.range(iterations)" makes a list-ish thing with "iterations" number of things from zero to "iterations -1". Look in any python reference for range() if you need more, and check the zope docs, too because _.range() is limited in zope for a fairly obvious reason.
home, home on the range()
-- Jim Washington
This answer is great! I guess the thing that puts me off about all the dtml/python stuff is the syntax of stuff I've never really seen in another programming language: an underscore then a dot to start the function off. I find that to be very strange. Thanks for the help! Russell
This answer is great! I guess the thing that puts me off about all the dtml/python stuff is the syntax of stuff I've never really seen in another programming language: an underscore then a dot to start the function off. I find that to be very strange.
For what I presume to be security reasons, DTML doesn't have access to the Python built-ins. Instead it uses a number of DTML functions which live in the DTML namespace (thus the underscore notation). You can see these at http://www.zope.org/Members/michel/ZB/AppendixA.dtml in the 'functions' section, as well as in your friendly Zope Help DTML reference. Granted this is a rather curious way of accessing its built-in functions. It should encourage you (nudge nudge) to work more with Python Scripts (which are much more like the Python we know and love). --jcc (definitely love) -- "It is concluded. Banquo, thy soul's flight, If it find heaven, must find it out tonight." http://jccooper.brown.rice.edu/
participants (3)
-
J. Cameron Cooper -
Jim Washington -
Russell Hires