[Zope] Zope Book -> Chap 3 -> Interest Rate Example

Sylvain Thénault Sylvain Thénault
Thu, 5 Jun 2003 14:51:35 +0200


On Thursday 05 June à 13:37, Simon Forster wrote:
> Yesterday I managed to instal Python and Zope. Today I'm learning how 
> to use Zope. I'm not 100% sure I understand the Zope model - but then 
> I'm only on chapter 3 and I'm sure many of my questions will be 
> answered later in the book. However, the interest rate example given in 
> the book returns an error to me:
> 
> "Zope Error
> 
> Zope has encountered an error while publishing this resource.
> 
> Error Type: KeyError
> Error Value: years"
> 
> This appears to be quite a simple error where the form value "years" is 
> not being seen by Zope. This error is thrown the first time "years" is 
> referenced. That is:
> 
> <span tal:content="years">2</span>
> 
> This code appears in a Page Template.
> 
> If I cut this code out, the page errors at the next form value 
> (principal).
> 
> Obviously I'm not "capturing" the form values submitted by the html 
> form. However, The "Page Template" object doesn't give you a method to 
> explicitly capture these form elements so I assume that this happens 
> automagically. An incorrect assumption?

yes. You should access the submitted form value using the request
variable :

<span tal:content="request/years">2</span>

or

<span tal:content="request/form/years">2</span>

(the first is a convenience method to transparently access request/form
attributes)

If you are not sure that the years field exists, you can use : 

<span tal:content="request/years | nothing">2</span>

to avoid exception when it doesn't exist.

-- 
Sylvain Thénault                               LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org