On Jan 16, 2011, at 2:42 PM, Kenneth Lundström wrote:
> 
> > 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).
> 
> I just added:
> 
> routers = dict(
>    BASE = dict(
>        domains = {
>            'economy.nudata.fi' : 'economy',
>            'testing.nudata.fi' : 'testapplication',
>        }
>    ),
> )
> 
> but if if go to economy.nudata.fi I get to welcome.

One more question: does this work OK with the old routing logic?

> 
> 
> Kenneth
> 
>> 
>> 
>> ======
>> 
>> 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.
> 


Reply via email to