Page Templates + python script example fromThe Zope Book
Hello all, I am trying to get the "interest rate calculator" example from chapter 3 of the Zope Book to work. I created an interestRateForm page template, an interestRateDisplayTemplate, and a python script, as described in the chapter (the code was copied directly from the book and is listed at the bottom of this email for reference). When I try to use the example by pointing my browser at the interestRateForm URL(this displays correctly), I give it some values as requested, then click the calculate button. The error I get is Error Type: Undefined Error Value: years not found in 'years', at line 5, column 6 If I comment out the first line referring to the "years" variable, ie <!-- <span tal:content="years">2</span> --> Then I get the slightly different but probably related error Error Type: TALESError Error Value: exceptions.NameError on global name 'principal' is not defined in '', at line 6, column 8 ie referring now to the spot in the interestRateDisplay template where the python script is actually called, with "principle" being the first argument to it. As far as I can guess, these variables are not being correctly passed from the interestRateForm template to the interestRateDisplay template. I haven't reaally been able to find anything explicit about how variables are passed between page templates, how the namespace works, etc. I tried to have a look at the REQUEST object, I inserted it using <span tal:content="request"> dummy request </span> I realise there must be a better way to do this , since this prints out a godawful mess full of html tags, however i *was* able to see that the various variables were there in the request object, ie: h3>form</h3><table><tr valign="top" align="left"><th>principal</th><td>10000.0</td></tr><tr valign="top" align="left"><th>periods Does anyone have any clues as to what I need to do next to make it work? Thanks :) Wendy Langer interestRateForm **************** <html> <body> <form action="interestRateDisplay" method="POST"> <p>Please enter the following information:</p> Your current balance (or debt): <input name="principal:float"><br> Your annual interest rate: <input name="interest_rate:float"><br> Number of periods in a year: <input name="periods:int"><br> Number of years: <input name="years:int"><br> <input type="submit" value=" Calculate "><br> </form> </body> </html> InterestRateDisplay ******************* <html> <body> <p>Your total balance (or debt) including compounded interest over <span tal:content="years">2</span> years is:</p> <p><b>$<span tal:content="python: here.calculateCompoundingInterest(principal, interest_rate, periods, years)">1.00</span></b></p> </body> </html> calculateCompoundInterest ************************* """ Calculate compounding interest. """ i = interest_rate / periods n = periods * years return ((1 + i) ** n) * principal
participants (1)
-
Wendy Langer