How to make turbogears.url answering something other than "localhost:8080"

5 views
Skip to first unread message

Jorge Godoy

unread,
Dec 1, 2005, 8:58:59 AM12/1/05
to TurboGears

Hi!


What's the setup that I have to do to be able to pass a relative URL to
"turbogears.url" (for using redirects with CherryPy) and have it include the
hostname, instead of using "localhost"?

Today when I issue a raise
cherrypy.HTTPRedirect(turbogears.url("/relative_url/")) it redirects me to
"http://localhost:8080/relative_url" instead of
"http://my.site.com/relative_url". If I hardcode the URL and use
cherrypy.HTTPRedirect("http://my.site.com/relative_url/") it works perfectly,
but then I loose the ability of "moving" things around easily (well, I need a
"sed" script to fix this for the production server, but that's just it...).


Thanks in advance,
--
Jorge Godoy <jgo...@gmail.com>

Jared Kuolt

unread,
Dec 1, 2005, 12:28:21 PM12/1/05
to turbo...@googlegroups.com
Jorge, what version are you running? I haven't been having this
problem, though I've been using an IP address on 0.8a4.
--
jared...@gmail.com

Jorge Godoy

unread,
Dec 1, 2005, 12:40:44 PM12/1/05
to turbo...@googlegroups.com
Jared Kuolt <jared...@gmail.com> writes:

> Jorge, what version are you running? I haven't been having this
> problem, though I've been using an IP address on 0.8a4.

SVN r.258.

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

Kevin Dangoor

unread,
Dec 1, 2005, 3:09:43 PM12/1/05
to turbo...@googlegroups.com
On 01 Dec 2005 11:58:59 -0200, Jorge Godoy <jgo...@gmail.com> wrote:
Are you proxying behind Apache or something? If so, this would make sense

You should be able to set server.webpath in your config file to
http://my.site.com

Kevin

Jorge Godoy

unread,
Dec 1, 2005, 3:17:46 PM12/1/05
to turbo...@googlegroups.com
Kevin Dangoor <dan...@gmail.com> writes:

> Are you proxying behind Apache or something? If so, this would make sense

Yes.

> You should be able to set server.webpath in your config file to
> http://my.site.com

I've tried that. It then replaces the URL with something like:
http://localhost:8080/http://my.site.com instead of http://my.site.com/ only.

--
Jorge Godoy <jgo...@gmail.com>
Message has been deleted

Dan Jacob

unread,
Dec 2, 2005, 2:40:57 AM12/2/05
to TurboGears
Try the baseURLFilter:

baseUrlFilter.on=True
baseUrlFilter.baseUrl = "http://my.site.com"

cherrypy.HTTPRedirect(turbogears.url("/relative_url/")) should then
work.

Kevin Dangoor

unread,
Dec 4, 2005, 2:30:29 PM12/4/05
to turbo...@googlegroups.com
Sounds like a bug. Can you drop that into the trac and set the milestone to 0.9?

Thanks,
Kevin

Arnar

unread,
Dec 5, 2005, 4:05:02 AM12/5/05
to TurboGears
Hello there,

I believe I might be experiencing the same bug. I'm running TurboGears
(latest stable version) behind Apache and mod_python via mpcp. My
problem is not with redirects though, but that I can't place the
application anywhere except on the virtual host root.

I want to place my application on a path like
http://www.server.is/application/ - but I get an 404 with the following
traceback:

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
"/usr/lib/python2.4/site-packages/CherryPy-2.1.0-py2.4.egg/cherrypy/_cphttptools.py",
line 748, in mapPathToObject
raise cherrypy.NotFound(path)
NotFound: 404: The path '/timaskraning/' was not found.

I've tried both baseUrlFilter and server.webpath, I even tried adding
the Cp-Location header to the request in httpd.conf. Nothing helps..

Am I doing something wrong?

Arnar

Jorge Godoy

unread,
Dec 5, 2005, 6:38:46 AM12/5/05
to turbo...@googlegroups.com
"Arnar" <arn...@gmail.com> writes:

> Kevin Dangoor wrote:
> > On 01 Dec 2005 18:17:46 -0200, Jorge Godoy <jgo...@gmail.com> wrote:
> > >
> > > Kevin Dangoor <dan...@gmail.com> writes:
> > >
> > > > Are you proxying behind Apache or something? If so, this would make sense
> > >
> > > Yes.
> > >
> > > > You should be able to set server.webpath in your config file to
> > > > http://my.site.com
> > >
> > > I've tried that. It then replaces the URL with something like:
> > > http://localhost:8080/http://my.site.com instead of http://my.site.com/ only.
> >
> > Sounds like a bug. Can you drop that into the trac and set the milestone to 0.9?
> >
> > Thanks,
> > Kevin

Hmmm... I haven't read Kevin's message. I'll post it to Trac.

Arnar, can you add your comments later? I'll post the ticket number here.

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

Jorge Godoy

unread,
Dec 5, 2005, 6:44:33 AM12/5/05
to turbo...@googlegroups.com
Jorge Godoy <jgo...@gmail.com> writes:

> Arnar, can you add your comments later? I'll post the ticket number here.

http://trac.turbogears.org/turbogears/ticket/179

It's ticket #179.


Be seeing you,
--
Jorge Godoy <jgo...@gmail.com>

Kevin Dangoor

unread,
Dec 5, 2005, 10:11:19 AM12/5/05
to turbo...@googlegroups.com
Hi Arnar,

It sounds like there are two things in your case:

1) you should use the url function to make sure that the server path
gets added to URLs in your program
2) the url function has a bug that needs fixing (which is the ticket
Jorge opened).

Kevin
--
Kevin Dangoor
Author of the Zesty News RSS newsreader

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

Arnar Birgisson

unread,
Dec 6, 2005, 5:49:17 AM12/6/05
to turbo...@googlegroups.com
Hi there,

> It sounds like there are two things in your case:
>
> 1) you should use the url function to make sure that the server path
> gets added to URLs in your program
> 2) the url function has a bug that needs fixing (which is the ticket
> Jorge opened).

I seem to have "fixed" my problem, don't know if it's the proper way
or I just stumbled upon a workaround.

My site works by adding the following filter to my controllers _cpFilterList:

class VirtualPathFilter(object):
def beforeRequestBody(self):
if cherrypy.config.get("virtualPathFilter.on", False):
prefix = cherrypy.config.get("virtualPathFilter.prefix", "")
if prefix:
path = cherrypy.request.path
if path == prefix:
path = "/"
elif path.startswith(prefix):
path = path[len(prefix):]
cherrypy.request.path = path

and the following to my config:

virtualPathFilter.on = True
virtualPathFilter.prefix = "/timaskraning"

To get ${std.url(...)} to work I had to set this also:
server.webpath="timaskraning"

I'll post my stack-trace above and a reference to this thread in the ticket.

Arnar
Reply all
Reply to author
Forward
0 new messages