On Jan 16, 2011, at 1:57 PM, Kenneth Lundström wrote: > > how do I test the new router that Jonathan has made. > > I renamed the routes.examples.py to routes.py and edited it. No mather what I > write in it gets used. I tried to find the answer in all posts on the > mailinglist but no success.
Start with router.example.py instead. The key to using the new router is to define a dict named 'routers'. There's more documentation in the file, and I'll repost some examples below. Post your routes.py here, along with a description of what you intend that it does (if it's not obvious). ====== Suppose you've written an app, named it 'myapp', and want to make it the default, with its name always removed. Your default controller is still 'default', and you want to remove its name from user-visible URLs as well. Here's what you put in routes.py: routers = dict( BASE = dict( default_application='myapp' ), ) That's it. And it's smart enough to know how to do the right thing with URLs like: http://domain.com/myapp/default/myapp or http://domain.com/myapp/myapp/index ...where normal shortening would be ambiguous. If you have two applications, myapp and myapp2, you'll get the same effect, and additionally myapp2's default controller will be stripped from the URL whenever it's safe (which is mostly all the time). Another case. Suppose you want to support URL-based languages, where your URLs look like this: http://myapp/en/some/path or (rewritten) http://en/some/path Here's how: routers = dict( BASE = dict( default_application='myapp' ), myapp = dict( languages=['en', 'it', 'jp'], default_language='en' ), ) Now an incoming URL like this: http:/domain.com/it/some/path will be routed to /myapp/some/path, and request.uri_language will be set to 'it', so you can force the translation. You can also have language-specific static files. http://domain.com/it/static/filename will be mapped to: applications/myapp/static/it/filename ...if that file exists. If it doesn't, then URLs like: http://domain.com/it/static/base.css ...will still map to: applications/myapp/static/base.css (because there is no static/it/base.css) So you can now have language-specific static files, including images, if you need to. Domain mapping is supported as well. routers = dict( BASE = dict( domains = { 'domain1.com' : 'app1', 'domain2.com' : 'app2', } ), ) does what you'd expect. routers = dict( BASE = dict( domains = { 'domain.com:80' : 'app/insecure', 'domain.com:443' : 'app/secure', } ), ) ...maps http://domain.com accesses to app's controller named 'insecure', while https accesses go to the 'secure' controller. Or you can map different ports to different apps, in the obvious way. There's more, but mostly everything happens automatically, and there's no need to dig into the details of configuration unless there's some non-standard thing you need. There's a bit more documentation in router.example.py.