Skip to content

Instantly share code, notes, and snippets.

@amcgregor
Created January 15, 2011 08:00
Show Gist options
  • Save amcgregor/780774 to your computer and use it in GitHub Desktop.
Save amcgregor/780774 to your computer and use it in GitHub Desktop.
An example of dynamic dispatch.
class User(Controller):
def __init__(self, id):
self.id = id
def index(self):
return 'mypkg.views.user', dict(id=self.id)
def method(self):
return 'mypkg.views.method', dict(id=self.id)
class Users(Controller):
def index(self):
return 'mypkg.views.users', dict(...)
def __lookup__(self, id, *remainder, **args):
return User(id), remainder
class Root(Controller):
users = Users()
def index(self):
return 'mypkg.views.root', dict()
def action(self):
return ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment