Routes: subdomains and url()

3 views
Skip to first unread message

Chris

unread,
Dec 29, 2009, 6:47:44 PM12/29/09
to pylons-discuss
In routes, I'd like to require subdomains on my named routes for url
matching. However, when generating urls with url(), I don't want to
supply the sub_domain keyword argument every time (every url I have is
subdomained). I would rather it
1) use the current subdomain
Or
2) if sub_domain kwarg is not given, just generate the end portion,
like /events/index instead of the full url http://foo.com/events/index

For 1, I thought using url.current() would work, but after reading
URLGenerator's code, I realized that named routes do not honor the
`url.current` concept due to the branching structure in `generate`, so
I assume named routes aren't meant to support `url.current`?

For 2, I went ahead and modified `util._subdomain_check` to just
generate the trailing portion of the url if sub_domain is not
explicit. The way the urls work when browsing the current subdomain.
That is, current url might be http://texas.domain.com/howdy/yall, then
calling url('goodbye'), can just generate the '/yall/comebacknow'
piece and the url works.

def _subdomain_check(...):
if mapper.sub_domains:
subdomain = kargs.pop('sub_domain', None)
# just generate regular url if sub is not given explicity
if subdomain is None:
return kargs
# carry on...

Reply all
Reply to author
Forward
0 new messages