views:

187

answers:

2

I need to know the full url for the current page from within a Mako template file in Pylons.

The url will be using in an iframe contained within the page so it needs to be known when the page is being generated rather than after the page hits the server or from the environment. (Not sure if I am communicating that last bit properly)

A: 

I think you can use h.url_for('', qualified=True) to get the full URL. Make sure you have imported url_for in your helper file: from routes.util import helpers as h

Have a look at http://pylonshq.com/docs/en/0.9.7/thirdparty/routes/#routes.util.url_for

Glen Robertson
Thanks for the idea...I tried it but I am actually using this in an iframe and your code gave the url for the iframe and not the containing page. Will update the question in that regard.
Jesse
Hmm, if it is an iframe, then it would not have any knowledge of the outer page URL. the only way might be to use javascript to get the URL of the page, (using window.location).
Glen Robertson
Yeah, the answer I posted seems to work. I am going to leave the question open a little longer though to see if anyone else has an idea. Thanks again for helping!
Jesse
+1  A: 

Not sure if this is the Pylons way of doing things but ${request.url} seems to work for me.

Jesse
Another very similar way would be to assign the request.url to the context global, "c", in the controller's action and then use "c" in the view.
Shao