ObjectApplication

The ObjectApplication matches the request URL against a tree of Python objects:

from colubrid import ObjectApplication, execute

class Blog(object):
    def index(self):
        pass
    def entry(self, id):
        pass
    def archive(self, year, month=False):
        pass
    archive.container = True

class Pictures(object):
    def index(self):
        pass
    def detail(self):
        pass

class Paste(object):
    def index(self, id=None):
        pass

class DispatcherApplication(ObjectApplication):
    root = Blog
    root.pictures = Pictures
    root.paste = Paste

app = DispatcherApplication

if __name__ == '__main__':
    execute()

When you visit http://localhost:8080/, it will call Blog.index without arguments. When called http://localhost:8080/entry/1, Colubrid calls Blog.entry with "1" as parameter.

The archive.container = True assignment forces container behavior, which means that Colubrid appends a trailing slash to the URL.

Last Change: 10 Sep 2006 17:12:26 | show source