If you use Cheetah, please support the project and register by clicking here:


14.5 Initializing your template-servlet with Python code

If you need a place to initialize variables or do calculations for your template-servlet, you can put it in an .awake() method because WebKit automatically calls that early when processing the web transaction. If you do override .awake(), be sure to call the superclass .awake method. You probably want to do that first so that you have access to the web transaction data Servlet.awake provides. You don't have to worry about whether your parent class has its own .awake method, just call it anyway, and somebody up the inheritance chain will respond, or at minimum Servlet.awake will respond. Section 13.4 gives examples of how to call a superclass method.

As an alternative, you can put all your calculations in your own method and call it near the top of your template. (#silent, section 7.2).

If you use Cheetah, please support the project and register by clicking here: