On Apr 2, 2007, at 5:10 PM, Mike Orr wrote:
> How do I generate routes with fragments? My site has the following
> URLs:
>
> /glossary/index - Main page.
> /glossary/A - All entrie staring with "A".
> /glossary/A#term - A specific entry.
> /glossary/references - Bibliography.
>
> I need to generate a URL for a specific term. My routing rule is:
>
> map.connect("glossary", "/glossary/:page", controller="main",
> action="glossary", page="index")
>
> Can I use url_for to generate the fragment, possibly by adding another
> routing rule? Or do I have to generate the letter URL and then add
> the fragment manually?
url_for can add in a URL anchor when one is provided as the anchor
keyword.
> This rule doesn't work:
>
> map.connect("glossary_term", "/glossary/:page#:term",
> controller="main",
> action="glossary", page="index")
>
> sre_constants.error: bad character in group name.
Yes, I hadn't really seen anyone using the page anchor to control
dispatch. I also was missing a unit test for this, which reveals that
you found a bug! Wooo!! Clearly an anchor like # should be treated
like '/'. I've added this capability in Routes trunk, which will let
the map.connect statement there work just fine, and it'll add in the
anchor as needed. Note that this will make it possible to have double
anchor's should you use a route that has an anchor in it, and send in
the anchor keyword to url_for.
Cheers,
Ben
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---