Chapter 17.5.1. expose()

The TurboGears expose() decorator is an extension to CherryPy’s expose decorator. It controls not only what methods should be accessible from the outside world but also how the output will be formatted. TurboGears uses the generic function mechanism from Philip Eby’s RuleDispatch package. And much of the power and flexibility of the TurboGears implementation of the expose decorator is a result of the inherent flexibility of generic functions.

One of TurboGear’s fundamental goals was to allow us to have a number of different “views” of the same controller method, just by adding additional expose decorators like this:

@expose("cheetah:mypackage.templates.text", as_format="text") @expose("mypackage.templates.xml", ...

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.