On Mar 24, 2011, at 9:57 AM, Martín Mulone wrote:
> For example I have a blog application with this url
>
> http://www.mysite.com/blog/default/post/2010/10/10/my-article
>
> I can short to this:
>
> http://www.mysite.com/blog/2010/10/10/my-article
>
> with this one route:
>
> (r'.*:/blog/(?P(19|20)\d\d[- /.](0[1-9]|1[012])[-
> /.](0[1-9]|[12][0-9]|3[01]).*)$',r'/blog/default/post/\g')
>
> Not easy to read :) if I can make it transparent to the user that the user
> not have to worried about routes.
You can do this with the new router if you make post the default function of
the blog app, and create a list of functions in blog/default. Something like
this:
routers = dict(
blog = dict(
default_function='post',
functions=['index', 'user', 'post', 'whatever'],
),
)
You'll need to parse and validate the args in default/post.
By specifying a list of functions in the default controller, you're telling the
router that it can unambiguously omit the 'post' name if there's no conflict.
So with the router above, a URL like /blog/default/post/index would *not* be
shortened to /blog/index, because that would conflict with the function named
'index'.
>
> 2011/3/24 Martín Mulone <[email protected]>
> Yes but not in the application folder. The importance is to be distributed
> with the application.
>
> 2011/3/24 Anthony <[email protected]>
> I believe this is already possible, no?
>
> The book describes app-specific routing for the old system:
> http://web2py.com/book/default/chapter/04#Pattern-Based-System
>
> And for the new system, the router.example.py file
> (http://code.google.com/p/web2py/source/browse/router.example.py) mentions
> you can have an app-specific router in applications/app/routes.py.
>
> Anthony
>
> On Thursday, March 24, 2011 11:49:58 AM UTC-4, Martin.Mulone wrote:
> I really want to see routes in the application folder. Routes in the past was
> hard to follow, now I think the work of Johnatan make it more easy. But when
> you have many applications, the routes for all is a bit messy. I don't know
> if this can be done:
>
> For example a simple case:
>
> Main routes.py:
> ---------------
>
> Domain Application
> ---------------------------------
> www.domain1.com domain1
> www.domain2.com domain2
>
>
>
> Aplication: applications/domain1/routes.py:
> -------------------------------------------
>
>
> [routes In]
> In Out
> ----------------------------------
> /favicon.ico /static/favicon.ico
>
>
> [routes Out]
> In Out
> ----------------------------------
> default/index /
> plugin_i2p/view/333 /view/333
>
>
> 2011/3/24 VP <[email protected]>
>
> Noticing the version of web2py keeps interestingly increasing to 2.0,
> I think this is something Massimo might want to spend sometime
> thinking about.
>
> As I understand it, because of "exec", controllers are called *after*
> the request arrives. This allows web2py to do a few interesting
> things that other frameworks can't.
>
> On the other hands, this is an example that shows an advantage of
> being able to manipulate controllers (concisely) *before* the request
> arrives.
>
> I found myself constantly type checking controller arguments (e.g.
> making sure an "id" is a number). This is another example where being
> able to specify a certain syntax to the URL is very helpful.
>