Get a full URL?

121 views
Skip to first unread message

Lion Kimbro

unread,
Dec 26, 2005, 11:50:37 PM12/26/05
to TurboGears
How can I get a full URL?

turbogears.url("/") will give you "/".

...but what if you want "http://localhost:8080/" instead?

Elvelind Grandin

unread,
Dec 27, 2005, 6:08:09 AM12/27/05
to turbo...@googlegroups.com
cherrypy.request.base + cherrypy.request.path

would give you the full URL request.


--
cheers
elvelind grandin

Kevin Dangoor

unread,
Dec 27, 2005, 9:06:07 AM12/27/05
to turbo...@googlegroups.com

We could probably change it to give full URLs if you use an absolute
URL like that. But can I ask why you need the full URL?

Kevin

--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: k...@blazingthings.com
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Jorge Godoy

unread,
Dec 27, 2005, 9:51:41 AM12/27/05
to turbo...@googlegroups.com
Kevin Dangoor <dan...@gmail.com> writes:

> We could probably change it to give full URLs if you use an absolute
> URL like that. But can I ask why you need the full URL?

Wouldn't it solve that problem of redirection that was reported a while ago?

--
Jorge Godoy <jgo...@gmail.com>

Kevin Dangoor

unread,
Dec 27, 2005, 9:56:06 AM12/27/05
to turbo...@googlegroups.com
On 27 Dec 2005 12:51:41 -0200, Jorge Godoy <jgo...@gmail.com> wrote:
>
> Kevin Dangoor <dan...@gmail.com> writes:
>
> > We could probably change it to give full URLs if you use an absolute
> > URL like that. But can I ask why you need the full URL?
>
> Wouldn't it solve that problem of redirection that was reported a while ago?

Assuming we're thinking of the same thing, those problems were caused
by server.webpath not being computed or added to the URL properly. I
believe that's been fixed... that may actually be the best solution to
this particular question as well: if Lion sets the server.webpath
variable that should appear at the beginning of the URL.

Jorge Godoy

unread,
Dec 27, 2005, 10:07:48 AM12/27/05
to turbo...@googlegroups.com
Kevin Dangoor <dan...@gmail.com> writes:

> Assuming we're thinking of the same thing, those problems were caused
> by server.webpath not being computed or added to the URL properly. I
> believe that's been fixed... that may actually be the best solution to
> this particular question as well: if Lion sets the server.webpath
> variable that should appear at the beginning of the URL.

The problema was having something like
"http://localhost:8080/http://some.thing.com/" as the result of the expansion
on the URL. (Ticket #179 - http://trac.turbogears.org/turbogears/ticket/179)

--
Jorge Godoy <jgo...@gmail.com>

Kevin Dangoor

unread,
Dec 27, 2005, 10:56:40 AM12/27/05
to turbo...@googlegroups.com

Ahh... That is basically the same thing. Did you try server.webpath?

We should be able to change turbogears.url to include the server info
from cherrypy (that Elvelind mentioned) if there's no server.webpath
set and you request an absolute url (something starting with "/").

Kevin

Elvelind Grandin

unread,
Dec 27, 2005, 11:10:08 AM12/27/05
to turbo...@googlegroups.com
Isn't the idea with url() to give you an absolut url?


--
cheers
elvelind grandin

Jorge Godoy

unread,
Dec 27, 2005, 11:10:32 AM12/27/05
to turbo...@googlegroups.com
Kevin Dangoor <dan...@gmail.com> writes:

> Ahh... That is basically the same thing. Did you try server.webpath?

Nope. I didn't. I'll try it again.

> We should be able to change turbogears.url to include the server info
> from cherrypy (that Elvelind mentioned) if there's no server.webpath
> set and you request an absolute url (something starting with "/").

Hmmm... This would eliminate the need of setting up server.webpath, wouldn't
it?

--
Jorge Godoy <jgo...@gmail.com>

Jorge Godoy

unread,
Dec 27, 2005, 11:11:41 AM12/27/05
to turbo...@googlegroups.com
Elvelind Grandin <elve...@gmail.com> writes:

> Isn't the idea with url() to give you an absolut url?

I'd add to that: a full URL, including the protocol (http or https) used and
server name? ;-)

--
Jorge Godoy <jgo...@gmail.com>

Elvelind Grandin

unread,
Dec 27, 2005, 11:13:09 AM12/27/05
to turbo...@googlegroups.com
if the url is absolute then there is no harm in giving the full url instead.


--
cheers
elvelind grandin

Jorge Godoy

unread,
Dec 27, 2005, 11:16:55 AM12/27/05
to turbo...@googlegroups.com
Jorge Godoy <jgo...@gmail.com> writes:

> Kevin Dangoor <dan...@gmail.com> writes:
>
> > Ahh... That is basically the same thing. Did you try server.webpath?
>
> Nope. I didn't. I'll try it again.

I just set up

server.webpath="https://my.server.com/"

and reloaded one page, without any special condition or redirect and then I
got:


Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/CherryPy-2.1.0-py2.4.egg/cherrypy/_cphttptools.py", line 271, in run
main()
File "/usr/lib/python2.4/site-packages/CherryPy-2.1.0-py2.4.egg/cherrypy/_cphttptools.py", line 497, in main
page_handler, object_path, virtual_path = mapPathToObject(path)
File "/home/godoy/desenvolvimento/python/TurboGears/trunk/turbogears/startup.py", line 188, in mapPathToObject
return cherrypy._cphttptools._mapPathToObject(path)
File "/usr/lib/python2.4/site-packages/CherryPy-2.1.0-py2.4.egg/cherrypy/_cphttptools.py", line 754, in mapPathToObject
if path[-1] != '/':
IndexError: string index out of range


--
Jorge Godoy <jgo...@gmail.com>

Kevin Dangoor

unread,
Dec 27, 2005, 12:15:50 PM12/27/05
to turbo...@googlegroups.com
On 12/27/05, Elvelind Grandin <elve...@gmail.com> wrote:
>
> Isn't the idea with url() to give you an absolut url?

The original idea was just to make sure that an application root was
taken care of (and to provide an easy mechanism for building query
strings). Giving a complete, absolute URL (at least in cases where the
parameter to url() begins with "/") seems reasonable...

Kevin

Kevin Dangoor

unread,
Dec 27, 2005, 12:18:19 PM12/27/05
to turbo...@googlegroups.com

server.webpath is actually less about setting the host and more about
the stuff that comes after the host but before TurboGears.

http://foo.bar/path/to/turbogears/YourController/doSomething

that "/path/to/turbogears" part needs to be there on absolute URLs.

server.webpath also (in svn) should remove the /path/to/turbogears
part so that CherryPy doesn't get confused.

Kevin Dangoor

unread,
Dec 27, 2005, 12:18:58 PM12/27/05
to turbo...@googlegroups.com
On 27 Dec 2005 14:16:55 -0200, Jorge Godoy <jgo...@gmail.com> wrote:
> IndexError: string index out of range

Looks like we need to add another test case...

Elvelind Grandin

unread,
Dec 27, 2005, 12:26:51 PM12/27/05
to turbo...@googlegroups.com
On 12/27/05, Kevin Dangoor <dan...@gmail.com> wrote:
>

Yes. but if I supply a url url() it needs get converted to an absolute
url in order for url() to prepend the approot, no?

--
cheers
elvelind grandin

Kevin Dangoor

unread,
Dec 27, 2005, 12:31:42 PM12/27/05
to turbo...@googlegroups.com
On 12/27/05, Elvelind Grandin <elve...@gmail.com> wrote:
> Yes. but if I supply a url url() it needs get converted to an absolute
> url in order for url() to prepend the approot, no?

There are too many "url"s in that sentence :)

Here's what I mean:

url("/foo") currently yields:
server.webpath + path to app root + "/foo"

If server.webpath is empty and there's no app root, you just get "/foo".

If there is an app root, you might get "/app/root/foo".

For most things, you really don't need to specify the server itself.

Elvelind Grandin

unread,
Dec 27, 2005, 12:37:11 PM12/27/05
to turbo...@googlegroups.com
On 12/27/05, Kevin Dangoor <dan...@gmail.com> wrote:
>
> On 12/27/05, Elvelind Grandin <elve...@gmail.com> wrote:
> > Yes. but if I supply a url url() it needs get converted to an absolute
> > url in order for url() to prepend the approot, no?
>
> There are too many "url"s in that sentence :)
>
> Here's what I mean:
>
> url("/foo") currently yields:
> server.webpath + path to app root + "/foo"
>
> If server.webpath is empty and there's no app root, you just get "/foo".
>
> If there is an app root, you might get "/app/root/foo".
>
> For most things, you really don't need to specify the server itself.

I follow you so far.
but what if you do url("foo")
that would yield an absolute path to right?

> Kevin
>
> --
> Kevin Dangoor
> Author of the Zesty News RSS newsreader
>
> email: k...@blazingthings.com
> company: http://www.BlazingThings.com
> blog: http://www.BlueSkyOnMars.com
>


--
cheers
elvelind grandin

Kevin Dangoor

unread,
Dec 27, 2005, 12:46:09 PM12/27/05
to turbo...@googlegroups.com
On 12/27/05, Elvelind Grandin <elve...@gmail.com> wrote:
> I follow you so far.
> but what if you do url("foo")
> that would yield an absolute path to right?

nope. relative urls stay relative. If you just say "foo", the browser
will fill in the server name and app root by itself.

Kevin

Elvelind Grandin

unread,
Dec 27, 2005, 1:29:26 PM12/27/05
to turbo...@googlegroups.com
On 12/27/05, Kevin Dangoor <dan...@gmail.com> wrote:
>

ehum. yes I feel stupid now :P
ofcourse you'r right.
then the question is. should it return the protocol when the path is
absolute? in that case I have a patch ready to commit

Kevin Dangoor

unread,
Dec 27, 2005, 2:03:05 PM12/27/05
to turbo...@googlegroups.com
On 27 Dec 2005 14:16:55 -0200, Jorge Godoy <jgo...@gmail.com> wrote:
> I just set up
>
> server.webpath="https://my.server.com/"

Something that just occurred to me is that it's possible that
server.webpath isn't supposed to have the actual server name... just
the stuff that comes after the server name, but before CherryPy. That
could explain the error you saw.

Kevin

Kevin Dangoor

unread,
Dec 27, 2005, 2:05:22 PM12/27/05
to turbo...@googlegroups.com
On 12/27/05, Elvelind Grandin <elve...@gmail.com> wrote:
> ehum. yes I feel stupid now :P
> ofcourse you'r right.
> then the question is. should it return the protocol when the path is
> absolute? in that case I have a patch ready to commit

Sure, if we can reliably add the server name and everything in front
of absolute URLs, I see no harm in doing so.

(be sure to run the tests, because I'm pretty sure that the tests
don't always include the server name...)

Kevin

Jorge Godoy

unread,
Dec 27, 2005, 2:31:20 PM12/27/05
to turbo...@googlegroups.com
Kevin Dangoor <dan...@gmail.com> writes:

I just added "/" and got the same error... And I also got it with "/test/",
that should be a 'valid' webpath.

--
Jorge Godoy <jgo...@gmail.com>

Lion Kimbro

unread,
Dec 28, 2005, 1:29:16 AM12/28/05
to TurboGears
> But can I ask why you need the full URL?

Yes.

Because the site is constructing a bookmarklet. The user is going to be
somewhere else on the web when they click it.

Kevin Dangoor

unread,
Dec 28, 2005, 9:10:15 AM12/28/05
to turbo...@googlegroups.com

OK. That is indeed a good reason that I hadn't considered. Sounds like
Elvelind has a change to make this work.

Reply all
Reply to author
Forward
0 new messages