On Jun 19, 2010, at 9:11 AM, Christopher Steel wrote:

> I use a link from init to my app as well. Works great for me. You just
> need to set up your app name. I have not tried the routes way as of
> yet.

Here's something I've been using. I've added comments that I hope are clear. 

My intent here is to have a default app, controller and function: 
/myapp/default/index in this case (note that default/index is also web2py's 
default), while allowing other known apps. I want to strip as much of 
/myapp/default/index as possible outbound, and of course reattach them inbound.

BTW, it's useful to think of this backwards. That is, write routes_out first, 
and then write routes_in to handle everything you do in routes_out, along with 
special cases (files in static/, say)..

It's a little subtle.


routes_in = (

#  route "domain.com" or "domain.com/" to myapp (instead of init)
#
('/?', '/myapp/'),

#  recognize all the apps in the system, with or without trailing arguments
#
('/(?P<app>(admin|examples|welcome|myapp))','/\g<app>/'),
('/(?P<app>(admin|examples|welcome|myapp))/(?P<any>.*)','/\g<app>/\g<any>'),

#  route bare requests for favicon or robots.txt to myapp/static
#
('/favicon.ico', '/myapp/static/img/favicon.ico'),
('/robots.txt', '/myapp/static/robots.txt'),

#  recognize myapp's controllers
#
('/(?P<ctlr>(sysadmin|appadmin|css|static|init\\b))(?P<any>.*)', 
'/myapp/\g<ctlr>\g<any>'),

#  treat anything else as a function in /myapp/default
#
('/(?P<any>.*)','/myapp/default/\g<any>'),
)

routes_out = (

#  recognize outgoing known apps and don't strip them
#
('/(?P<app>(admin|examples|welcome))/(?P<any>.*)','/\g<app>/\g<any>'),

#  handle myapp's default controller with no fcn, etc
#
('/myapp(/default)?/?', '/'),

#  handle myapp's default controller and default fcn, etc
#
('/myapp(/default(/index)?)?/?', '/'),

#  handle myapp's default controller with other fcns, etc
#
('/myapp/default/(?P<any>.*)','/\g<any>'),

#  handle myapp's other controllers
#
('/myapp/(?P<any>.*)','/\g<any>'),
)

Reply via email to