spyce
         
home     documentation     download     Spyce logo


Examples

examples/handlervalidate.spy
[[!
def calculate(self, api, x):
    from spyceException import HandlerError
    try:
        x = float(x)
    except ValueError:
        raise HandlerError('Value', 'Please input a number')
    if x < 0:
        raise HandlerError('Value', 'Cannot take the square root of negative numbers!')
    self.result = x ** 0.5
]]

<spy:parent title="Active Handler Validation" />
<f:form>
    <f:text name="x" default="-1" label="Value:" />
    <f:submit handler="self.calculate" value="Square root" />
</f:form>

<p>
Result: [[= hasattr(self, 'result') and self.result or '(no result yet)' ]]
</p>
Run this code

Back to List of Examples


Spyce logo
Python Server Pages
version 2.1.3
Spyce Powered SourceForge Logo