How to find out the full URL
I have a page template, say 'products.pt', which takes traverse_subpath[0] as one of the variables, so e.g. the URL: http://myserver/products/100 will actually call products.pt, which get 100 from the URL and displays it in the template. Now my question is how can I get the full URL from within the tempalte 'products.pt'? If I use 'request/URL' it will show 'http://myserver/products' only, with the subpath somehow dropped. How can I get the '/100' part back? Ideally, I'd like to get back the whole URL as entered in the browser as a string. From the REQUEST I have to put together URL and QUERY_STRING, and the section (#xxx) part of the url can not be found in REQUEST. Thanks for helping. Hong Yuan
Hong Yuan wrote:
I have a page template, say 'products.pt', which takes traverse_subpath[0] as one of the variables, so e.g. the URL: http://myserver/products/100 will actually call products.pt, which get 100 from the URL and displays it in the template.
Now my question is how can I get the full URL from within the tempalte 'products.pt'? If I use 'request/URL' it will show 'http://myserver/products' only, with the subpath somehow dropped. How can I get the '/100' part back?
If you simply print the request object, you'll see everything available. The CGI environment variables are available: http://hoohoo.ncsa.uiuc.edu/cgi/env.html You can use ACTUAL_URL or URL0 to get the full url+path. You can use PATH_TRANSLATED or PATH_INFO to get just the path portion. You can use QUERY_STRING to get the query string.
Ideally, I'd like to get back the whole URL as entered in the browser as a string. From the REQUEST I have to put together URL and QUERY_STRING, and the section (#xxx) part of the url can not be found in REQUEST.
Unfortunately the CGI vars don't make provision for the anchor component or the whole unaltered URL. Don't even know it that's possibly without modifying ZPublisher. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/
Ideally, I'd like to get back the whole URL as entered in the browser as a string. From the REQUEST I have to put together URL and QUERY_STRING, and the section (#xxx) part of the url can not be found in REQUEST.
Unfortunately the CGI vars don't make provision for the anchor component or the whole unaltered URL. Don't even know it that's possibly without modifying ZPublisher.
Just to add to this, it is not possible to get the #anchor section of the URL. Web browsers strip it off before sending the request to the web server, as it's a client side behaviour. I have confirmed this with IE6 and FireFox 1.0.3. -- Phillip Hutchings http://www.sitharus.com/ sitharus@gmail.com / sitharus@sitharus.com
J Cameron Cooper wrote:
If you simply print the request object, you'll see everything available. The CGI environment variables are available: http://hoohoo.ncsa.uiuc.edu/cgi/env.html
You can use ACTUAL_URL or URL0 to get the full url+path.
You can use PATH_TRANSLATED or PATH_INFO to get just the path portion.
You can use QUERY_STRING to get the query string.
Thanks for the information. I found out what I need is the variable VIRTURL_URL, which includes the complete URL typed into the browser, including the traverse_subpath components. Alternatively, I think I can use context.REQUEST.URL+'/'.join(context.REQUEST.traverse_subpath). -- HONG Yuan Homemaster Trading Co., Ltd. No. 601, Bldg. 41, 288 Shuangyang Rd. (N) Shanghai 200433, P.R.C. Tel: +86 21 55056553 Fax: +86 21 55067325 E-mail: hongyuan@homemaster.cn
Hong Yuan schrieb:
I have a page template, say 'products.pt', which takes traverse_subpath[0] as one of the variables, so e.g. the URL: http://myserver/products/100 will actually call products.pt, which get 100 from the URL and displays it in the template.
Now my question is how can I get the full URL from within the tempalte 'products.pt'? If I use 'request/URL' it will show 'http://myserver/products' only, with the subpath somehow dropped. How can I get the '/100' part back?
Ideally, I'd like to get back the whole URL as entered in the browser as a string. From the REQUEST I have to put together URL and QUERY_STRING, and the section (#xxx) part of the url can not be found in REQUEST.
Hi, something like this?: <http://webproducer.at/lab/show_url> The script is here: <http://mail.zope.org/pipermail/zope/2004-June/151466.html> HTH Tonico
participants (4)
-
Hong Yuan -
J Cameron Cooper -
Phillip Hutchings -
Tonico Strasser