For a little more advanced version of what Massimo just posted:

This allows you to use both.

URL(r=request, c=<controller>, f=.....)
and
URL(c=<controller>, f=<function>.....)

http://packages.python.org/web2py_utils/init.html#gurl
http://hg.thadeusb.com/Web/web2py_utils/file/697470f78d16/web2py_utils/utils.py#l11


The reason we have to pass the request to URL each time is because it
is just imported into the context. Since it is just a python function,
it has no knowledge of request.

Why can't we do something like gURL from within web2py? When building
the context, why can't we make URL a loaded function that will get
request passed to it, exactly how gURL works.

Effectively, we won't have to pass request into URL function anymore... ever.

If your interested, I can work on the patch.

--
Thadeus





On Wed, Jul 28, 2010 at 3:56 PM, mdipierro <mdipie...@cs.depaul.edu> wrote:
> 1) It is a bit more complex because of static, appadmin, and admin.
> You can map
>
> /function/var1/var2
>
> into
>
> /app/controller/function/var1/var2
>
> using a file routes.py
>  ------- begin file
> routes_in=[
>  ('/admin/$anything','/admin/$anything'),
>  ('/static/$anything','/app/static/$anything'),
>  ('/appadmin/$anything','/app/appadmin/$anything'),
>  ('/$anything','/app/default/$anything'),
> ]
> routes_out=[(y,x) for (x,y) in routes_in]
> ----- end file
>
> 2) in db.py define
>
> def url(f,args={},vars={}):
>      return URL(r=request,f=f,args=args,vars=vars)
> def go(f,args={},vars={},flash=''):
>      session.flash=flash
>      return go(url(f=f,args=args,vars=vars))
>
>
> and use
>
>    url('index')
>
> or
>
>   go('index',flash='you are being redirected')
>
> I do it all the time
>
> On Jul 28, 3:29 pm, VP <vtp2...@gmail.com> wrote:
>> I'm a newbie, so my questions probably have easy answers, but anyway.
>> Among a few things, there are two I don't understand and think can be
>> simplified.
>>
>> 1. this url:   app/controller/function/var1/var2
>>
>> For me at least, most of the time I probably have only one
>> controller.   If there is one controller, may be we should get rid of
>> "controller" in the url?    This will be sufficient: app/f/a/b/c
>>
>> 2.  Similarly, most of the time I have only one app (current app).
>> But I use URL() a lot and every time I have to pass in request like
>> this URL(r=request, f='foo').
>>
>> Why do I have to pass in request if I have only one app, one
>> controller?
>>
>> Furthermore, isn't request supposed to be global?  If so, do we have
>> to pass it in?
>

Reply via email to