On 27 Mar 2014, at 6:49 AM, Louis Amon <[email protected]> wrote:
> I'm trying to use the URL() function to connect to an external website's API,
> thus benefitting from web2py's HTML entity encoding feature.
>
> I wrote something like this :
>
> URL(scheme='http', domain='www.example.org', a='API', vars={'locality':'some,
> city'})
>
> and found that the encoded URL turns out like this :
> http://www.example.org/APP_NAME/API?locality=some%2C+city
>
> With APP_NAME being my current application in web2py...
>
>
> I found a monkeypatch solution like this :
> URL(scheme='http', domain='www.example.org', a='API', c=' ', f=' ',
> vars={'locality':'some, city'})
>
> Which gives me an ugly but functional URL :
> http://www.example.org/API/ / ?locality=some%2C+city
>
>
>
> Is there a more elegant solution to this ?
>
>
URL() doesn't anticipate being used to generate external URLs, only web2py
URLs. You'd be better off, I think, writing your own utility routine to do what
you're after. urllib.urlencode does the magic for your query string (vars).
So for your example, something like:
encodeURL("http://www.example.org", path=['API'], query={'locality':'some,
city'})
...would be pretty trivial to write (path is a list of URL path elements to be
suitable encoded and joined with '/').
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.