routes_in = (
('.*[a-zA-Z0-9]{6}', '/catchAll'),
)
#in default.py
def catchAll():pass
routes_in = ((r'^/?$', r'/app_name/default/index'),(r'^/(?P<url>[^/]*)/?$', r'/app_name/default/index/\g<url>'),)in your root-level routes.py The drawback is that you will lose access to all other apps (including admin) but that can be a good thing for public deployments.
routers = dict(
BASE = dict(
default_application = 'shortener',
default_controller = 'default',
default_function = 'index',
),
)
This is a neat solution Anthony (actually, it was my original idea for solving this). however I seem to be getting the same error: invalid function (default/tcgata).Forgive me, is this code in the root-level routes.py? or a routes.py in applications/shortener?Should anything else be in routes.py?
If I'm remembering this correctly, you want something like this (root level is fine):
routers = dict(
BASE = dict(
default_application = 'shortener',
),
shortener = dict(
default_controller = 'default',
default_function = 'index',
functions = ['index', 'user', 'download', 'call'],
),
)
...where the functions list is a complete list of the visible functions in the default controller (that is, any function that can appear in a URL).
The router needs that list so it can distinguish function names from args, and can then omit 'index'. Since in your example tcgata is not in the functions list, it can be safely treated as args[0].
Glad to hear it. Now that you've tested it, some color commentary for router users.
> routers = dict(
> BASE = dict(
> default_application = 'shortener',
> ),
BASE might better be named GLOBAL. It takes the default routing dict (see router.example.py) and modifies them as specified. In this case, we want to specify the default application, which needs to be done globally, at the base level.
> shortener = dict(
Following BASE, we specify routing parameters for specific apps. The effective router for any give app is the default router dictionary, updated by the BASE dictionary, updated by the app's dictionary (if any).
> default_controller = 'default',
> default_function = 'index',
These are actually the default values; they're only here for documentation, and aren't strictly necessary.
> functions = ['index', 'user', 'download', 'call'],
By default, the router scans the app's controllers directory to get the controller names, but it relies on the router dict for the function names. It wants them because it wants to map:
http://domain.com/foobar -> /shortener/default/index/foobar
http://domain.com/user -> /shortener/default/user
It does that by looking at the function candidates (foobar and user, above) and seeing whether they're in the functions list.
In outgoing URL() mapping, it uses the list to safely omit elements. So if args[0] is 'foobar', it can omit a/c/f safely. But suppose the function is 'index', but args[0] is 'user', which collides with a known function name. Now it knows that it can't safely omit the function name, and the outgoing URL becomes '/index/user'.
If you *don't* specify the functions list, then the outgoing URL drops the default function name (here 'index') only if args is empty.
> ),
> )