On Jan 6, 2011, at 11:52 AM, VP wrote:
>
> While this is intended to simplify the current specifications of
> routes.py (I think), what I have seen is more confusing to me. Does
> this replace the old routes.py?
Only if you define a routers dict.
>
> Maybe, can you provide examples of typical use cases? For example,
> one VPS account, each domain mapping to each app. Anything else?
routers = dict(
BASE = dict(
domains = {
"domain1.com" : "app1",
"domain2.com" : "app2",
"domain3.com" : "app3",
},
)
)
If you need to override any app-specific defaults (see router.example.py for
the defaults), you'd do it this way:
routers = dict(
BASE = dict(
domains = {
"domain1.com" : "app1",
"domain2.com" : "app2",
"domain3.com" : "app3",
},
)
app1 = dict(default_controller = "ctlr1")
)
There's an alternative syntax for domain mapping, exactly equivalent to the
above:
routers = dict(
app1 = dict(domain="domain1.com", default_controller="ctlr1")
app2 = dict(domain="domain2.com"),
app3 = dict(domain="domain3.com"),
)
These will give you full URL shortening. For example:
http://domain2.com/app2/default/fcn/abc/def
will (by default) become:
http://domain2.com/fcn/abc/def
...though the full URL will continue to work.
Root-static files (by default robots.txt and favicon.ico) will be mapped to the
static folder of the appropriate application (which is default_application if
domain mapping is not involved).
A URL like this:
http://domain2.com/admin/fcn/abc/def
...will be mapped correctly to:
http://domain2.com/admin/default/fcn/abc/def
(assuming that applications/admin is installed)
>
> Thank you.
>
>
>
> On Jan 6, 10:29 am, Jonathan Lundell <[email protected]> wrote:
>> The new router logic in the trunk is looking fairly stable now, and needs
>> feedback.
>>
>> See the comments in router.example.py for summary documentation (reproduced
>> below), and ask here if you have questions.
>>
>> The simplest possible router is:
>>
>> routers = dict()
>>
>> This sets all the defaults (including default_application=init). The next
>> most simple router:
>>
>> routers = dict(
>> BASE = dict(default_application = 'myapp')
>> )
>>
>> Either of those will perform component removal from outgoing URLs.
>>
>> If 'myapp' needs to override specific routing parameters, you'll do
>> something like this:
>>
>> routers = dict(
>> BASE = dict(default_application = 'myapp'),
>> myapp = dict(default_controller = 'defcon')
>> )
>>
>> To use the new language facility (URLs like /a/pt-br/c/f/...), you'll need
>> to do something like this early in your model:
>>
>> if request.uri_language: T.force(request.uri_language)
>>
>> This is not tested, and it'd be great if someone could give it a shot.
>> Notice that with language translation, static files are served
>> preferentially from language-specific subdirectories.
>>
>> applications/appname/static/pt-br/...
>>
>> If the incoming URL for a static file is tagged pt-br, we look first in
>> static/pt-br/ and then in static/, so it's not necessary to duplicate files
>> that don't need translation.
>>
>> If you're already using routes.py, just add a routers=dict(... entry, and it
>> will be used preferentially; you shouldn't have to remove your regex-based
>> rewrites.
>>
>> Feedback, please.
>>
>> # routers are dictionaries of URL routing parameters.
>> #
>> # For each request, the effective router is:
>> # the built-in default base router (shown below),
>> # updated by the BASE router in routes.py routers,
>> # updated by the app-specific router in routes.py routers,
>> # updated by the app-specific router from applcations/app/routes.py
>> routers (if any)
>> #
>> #
>> # Router members:
>> #
>> # default_application: default application name
>> # applications: list of all recognized applications, or 'ALL' to use all
>> currently installed applications
>> # Names in applications are always treated as an application names when
>> they appear first in an incoming URL.
>> # Set applications to [] to disable the removal of application names
>> from outgoing URLs.
>> # domains: dict used to map domain names to application names
>> # default_controller: name of default controller
>> # default_function: name of default function (all controllers)
>> # root_static: list of static files accessed from root
>> # (mapped to the selected application's static/ directory)
>> # domain: the domain that maps to this application (alternative to using
>> domains in the base router)
>> # languages: list of all supported languages
>> # Names in controllers are always treated as language names when they
>> appear in an incoming URL after
>> # the (optional) application name.
>> # controllers: list of valid controllers in selected app
>> # or "DEFAULT" to use all controllers in the selected app plus 'static'
>> # or [] to disable controller-name removal.
>> # Names in controllers are always treated as controller names when they
>> appear in an incoming URL after
>> # the (optional) application and language names.
>> # default_language
>> # The language code (for example: en, it-it) optionally appears in the
>> URL following
>> # the application (which may be omitted). For incoming URLs, the code
>> is copied to
>> # request.language; for outgoing URLs it is taken from
>> request.language.
>> # If languages=[], language support is disabled.
>> # The default_language, if any, is omitted from the URL.
>> # check_args: set to False to suppress arg checking
>> # request.raw_args always contains a list of raw args from the URL,
>> not unquoted
>> # request.args are the same values, unquoted
>> # By default (check_args=True), args are required to match args_match.
>> # acfe_match: regex for valid application, controller, function, extension
>> /a/c/f.e
>> # file_match: regex for valid file (used for static file names)
>> # args_match: regex for valid args (see also check_args flag)
>> #
>> #
>> # The built-in default router supplies default values (undefined members
>> are None):
>> #
>> # default_router = dict(
>> # default_application = 'init',
>> # applications = 'ALL',
>> # default_controller = 'default',
>> # controllers = 'DEFAULT',
>> # default_function = 'index',
>> # default_language = None,
>> # languages = [],
>> # root_static = ['favicon.ico', 'robots.txt'],
>> # domains = dict(),
>> # check_args = True,
>> # map_hyphen = True,
>> # acfe_match = r'\w+$', # legal app/ctlr/fcn/ext
>> # file_match = r'(\w+[-=./]?)+$', # legal file (path) name
>> # args_match = r'([\w@ -]+[=.]?)+$', # legal arg in args
>> # )
>> #
>> # See rewrite.map_url_in() and rewrite.map_url_out() for implementation
>> details.