Chapter 17.6.1. Validation Errors

Every method decorated by validate() requires a corresponding error handler. The most straightforward way to do so is to declare a function an error handler for a given method via the error_handler() decorator:

@validate(form=my_form)
@error_handler(my_eh)
def register(self, name=None, age=None, email=None):

The function declared as an error handler can have an arbitrary signature, but you might want to declare a parameter tg_errors wherein a mapping of argument names to errors will be passed. If the same error handler is used for multiple methods, an argument tg_source mapped to the method that triggered the error can prove useful.

Other parameters of interest are any named the same as arguments being validated, ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.