IntroductionGAEO routes your url in 3 ways by default: - / will be mapped to {'controller':'welcome', 'action':'index'}
- /foo/bar will be mapped to {'controller':'foo', 'action': 'bar'}
- /foo will be mapped to {'controller':'foo', 'action':'index'}
However, you can use gaeo.dispatch.route.Router to add routing rules. This page will introduce you how to use the Router and how to write your rules. How-toThe routing rules should be determined first before the request be processed. I suggest you to connect your rule in the main.py (or, your main handler) like this: # import the Router class
from gaeo.dispatch.router import Router
...
def initRoutes():
""" Initialize the URL routing rules """
r = Router() # get the Router instance (it's a singleton).
# map the /signup to the appropriate controller/action
r.connect('/signup', controller='account', action='signup')
# another rule
r.connect('/user/:id/:action', controller='user')
# map the pattern `/foo/bar/3` to FooController, bar method, and
# add a parameter id=3
r.connect('/:controller/:action/:id')
...NOTE that the Router will match the pattern in the order you connected. In the above sample, if you put r.connect('/:controller/:action/:id')before the r.connect('/user/:id/:action', controller='user')then, the url /user/1234/edit will be mapped to {'controller': 'user', 'action': '1234', 'id': 'edit'} and you will get a misroute.
|
Being a 'Rails Refugee', I like your approach. This is part of my urls.py file for a Django app:
Notice there are many complex situations that need to be handled, and notice also that almost all of the REST use cases can be handled with only three actions: SHOW, EDIT, and DELETE, based on a polymorphic approach of reading the arguments for the incoming request.
Bottom line: I vote for a RESTful approach of a very few controller actions (I use three, Rails uses seven), and the urls.py idea is actually very compact when you consider the variety of cases to handle.
Keep on going!
Wow! Please take a moment and re-format that last comment - I did not realize my like breaks would not come through, and I don't know where the bold came from...