views:

35

answers:

1

I need to generate a URL for use as a callback in an external system in my pylons application. This requires me to provide both the pylons-app-relative controller path (as generated by the url method:

>>> relative_url = url(controller='my_cont', action='callback', id=generated_id)
>>> print relative_url
/my_cont/callback/1234

However, I need the whole URL; hostname, relative paths (in case of mod_wsgi, where the path might include other parts from server configuration) &c.

How can I get that?

+1  A: 

You can use the routes function url_for, which takes a parameter for host:

from routes import url_for
from pylons import request

abs_url = url_for(host=request.host,
                  controller="my_cont",
                  action="callback",
                  id=gen_id)

Of course, this only works if the host is the same as the request's.

Hollister