On Feb 10, 2011, at 5:16 PM, Plumo wrote:
> so let's say I have mapped /init/default/about to /about
> 
> Then: URL(r=request, c='default', f='about', anchor='company')
> will produce: /init/default/about#company 
> instead of: /about#company

OK, I have some more information on this.

With the regex URL rewriter (which is the only one in the stable release), the 
anchor (and query string if there is one) is part of the URL being matched in 
routes_out. So you need to include it in your regex in order for it to work the 
way you want.

So for example instead of this:

routes_out = [
           ('/init/default/index', '/'), 
]

you need this:

routes_out = [
           (r'/init/default/index(?P<anchor>(#.*)?)', r'/\g<anchor>'), 
]

or more generally:

routes_out = [
           (r'/init/default/index(?P<query>(\?.*)?)(?P<anchor>(#.*)?)', 
r'/\g<query>\g<anchor>'), 
]

or combined, if you never need to distinguish the query and anchor:

routes_out = [
           (r'/init/default/index(?P<qa>([?#].*)?)', r'/\g<qa>'), 
]


FWIW, this doesn't arise with the new-style router in the trunk. The downside 
there is that you can't rewrite the query string or anchor.

Reply via email to