I cannot reproduce this problem. For me, 'laa%20poo' is converted to 'laa
poo' (i.e., the '%20' is properly converted to a space, not an underscore).
What version of web2py are you using? Are you using the built-in Rocket
server?
Anthony
On Thursday, July 14, 2011 6:27:09 AM UTC-4, (m) wrote:
> Awesome and thanx. I got that working and am able to generate URLs of
> the form I wanted.
>
> But I've now discovered that web2py seems to be doing some additional
> URL processing that I can't isolate.
>
> Assume a controller:
>
> def baz():
> orb = request.args[0]
> return dict(orb=orb)
>
> With a view that just renders orb:
>
> {{extend 'layout.html'}}
> <h1>Baz</h1>
> <p>{{=orb}}</p>
>
> When I type in a URL of the form:
>
> http://localhost:8000/simple_app/default/baz/laa%20poo
>
> the value of orb that gets passed to the view appears to be
>
> laa_poo
>
> In other words, the encoded space got converted to an underscore
> somewhere.
>
> Who is doing this and where are its rules documented? (I'm guessing
> it's part of a security measure to prevent arbitrary stuff being
> passed as args -- is this right?)
>
>
> On Jul 14, 2:31 am, Anthony <[email protected]> wrote:
> > If you've got keys and values in a dictionary that you want to convert to
> a
> > query string, you would use urllib.urlencode (which is what the web2py
> URL
> > function uses for vars). To quote just a plain string (like an arg), you
> can
> > use urllib.quote() or urllib.quote_plus() (the latter converts each space
> to
> > a '+' instead of a '%20'). If you want to convert back, you can use
> > urllib.unquote() or urllib.unquote_plus() (though I think that will be
> > handled automatically anyway).
> >
> > Anthony
> >
> > On Wednesday, July 13, 2011 5:55:49 PM UTC-4, (m) wrote:
> > > My Web-programming and Python noobs continues to show. Thanks for
> > > bearing with me.
> >
> > > I have a view with a fragment along the lines of the following to
> > > generates a list of links. foos has been generated in the controller.
> >
> > > {{for foo in foos:}}
> > > <li><a href="{{=URL('show', args=foo.name)}}">{{=foo.name}}</a></li>
> > > {{pass}}
> >
> > > This works fine until foo.name has spaces and/or other URL-unfriendly
> > > chars in it. So the questions are:
> >
> > > * Does web2py have its own mechanism for encoding/decoding URLs that
> > > is useful here?
> > > * If not, what is the preferred Python lib for doing URL encoding/
> > > decoding?
> >
> > > (P.S. I am aware that there are other ways of addressing this issue:
> > > e.g., use vars (which web2py seems to automatically encode) instead of
> > > args, or use args=foo.id instead or args=foo.name. In any event, it'd
> > > be good to know the web2py way to encode/decode URLs.)
> >
> >