Section 17.8. Summary


17.8. Summary

  • CherryPy maps URLs such as http://ocalhost/cart/item/delete to the object hierarchy of the "root" controller, so this URL would map to root.cart.item.delete().

  • CherryPy provides special routing for the index method, which is called (if it exists) whenever your URL maps to a class directly rather than one of its methods.

  • CherryPy also allows you to define a default method for a class, which is called whenever the URL does not match any of the methods of that class.

  • TurboGears has overloaded the @expose() decorator from CherryPy so it now controls not only which objects are published to the web, but also how the results of that object will be processed and returned to the user.

  • The @expose decorator uses RuleDispatch's generic functon system to allow you to define multiple possible output formats for the same controller. The most specific matching rule will be chosen, and that's what will be sent back to the user.

  • Multiformat outputs allow you to use the same controller method to provide HTML, XML RPC, JSON, and even SOAP output from the same controller. This makes creating web services easier, and also helps you create backward-compatible Ajax applications.

  • The @validate decorator allows you to preprocess input to 1) validate its contents, and 2) convert the contents to the proper kind of Python object that you need.

  • It's easy to create RESTful interfaces with CherryPy in a few lines of code. And if you have several different objects that will have the same style RESTful interface, you can create your own RESTful superclass to make your job even easier (and help you avoid repeating boilerplate code).




Rapid Web Applications with TurboGears(c) Using Python to Create Ajax-Powered Sites
Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites
ISBN: 0132433885
EAN: 2147483647
Year: 2006
Pages: 202

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net