[Tutor] Dynamically naming functions

Kent Johnson kent37 at tds.net
Mon Mar 13 13:49:44 CET 2006


Ed Singleton wrote:
> On 10/03/06, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
>>Dynamic site structure shouldn't need dynamic creation of functions
>>although the structure might need to be dynamically loaded into a
>>data structure in the code. It might also be a parameter of the functions.
> 
> 
> Doesn't CherryPy/TurboGears require Classes and Functions for it's
> data structures?  (Or parameters passed to them, of course).

CherryPy uses classes and functions as the foundation of the site 
hierarchy but the dynamic part of the site is usually handled by a 
function that processes parameters and generates a page, not by creating 
a function or class to handle every conceivable page.

> For website, I can't really see how I can not have a dynamic
> structure.  There's no way I'm writing a function for each "folder". 
> I do take your point though, however you often find that it's easy to
> maintain something dynamic than huge amounts of more static stuff (as
> in the difference between hundreds of static web pages and using a cms
> of some kind).

No, you don't have to do that, you create a handler at a relatively high 
level that knows how to respond to a request. See for example
http://www.cherrypy.org/wiki/PositionalParameters

and the section "Partial matches and the default method" in the tutorial:
http://www.cherrypy.org/wiki/CherryPyTutorial

Kent



More information about the Tutor mailing list