Chapter 17.6.2. Multiple Handlers

What if we want to handle certain validation errors differently than the rest? Fortunately, more than one error_handler() can be applied to a method. In such a scenario, the appropriate error handler is selected based on an arbitrary Python logical expression passed as a string via keyword argument rules. (Careful readers will note this is not unlike expose(); in fact, error_handler() is just an interface to an underlying generic function.)

@error_handler(pagenum_eh, "'num' in tg_errors")
@error_handler(content_eh)

The most specific applicable rule is selected, meaning if validation of num fails, pagenum_eh will be called regardless of the content’s state; or in other words, content_eh will be called if and ...

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.