On Jan 11, 2008 9:29 PM, MurphyTalk <[EMAIL PROTECTED]> wrote:
> I am new to Pylons (from Django), and am porting my personal blog site
> to Pylons. I had some problems on url_for() funcions,tried searching
> this group but no luck,so post my questions here to look for help.
>
> In my Pylons application there is a blog controller to handle all
> requests to the blog.I have the following routes configuration:
>
> map.connect('', controller='blog', action='page')
> map.connect('blog', controller='blog', action='page')
> map.connect(':controller/:action/:id')
>
> and I have two actions in controller blog : page and detail , to
> generate list of posts and detail of a post,respectively.
>
> So I can use h.url_for(controller='bog',action='detail',id=1) to
> generate a link to post 1,which is "/blog/detail/1". but in order to
> be consistent with my original site, I want it be like "/blog/1". I
> noticed if I omit the action argument,a default one 'index' would be
> used,thus instead of "/blog/1" I got "/blog/index/1" ... how can I get
> what I want?or I have to hand write the <a/> HTML tag?
First you need a route for /blog/1:
map.connect("blog/:id", controller="blog", action="detail")
This must be above the ":controller/:action/:id" route to prevent the
latter from matching it.
Now your url_for should work.
However, named routes are clearer, so I would do:
map.connect("home", "", controller="blog", action="page")
map.connect("blog", "blog/:id", controller="blog", action="page",
requirements={"id": r"\d+"})
map.connect(":controller/:action/:id")
url_for("home")
url_for("blog", id=2)
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---