[Zope] Current location: is my script reliable?
Tonico Strasser
contact_tonico at yahoo.de
Tue Jun 22 08:47:19 EDT 2004
Use case
I want to add fragement identifier like #xyz to a link and don't want
to reload the page and preserve the query strings when I click on it.
Example address: <https://www.example.com/foo/bar?x=y>
Why it doesn't work by default
By default, if I click on an anchor with '#xyz' a regular UA computes
https://www.example.com/foo/#xyz because Zope adds a <base>
tag to generated pages.
This little python script might help to get the "real" location, but I'm
not sure if it will work in all different setups and Zope versions:
request = context.REQUEST
server_url = request.get('SERVER_URL')
path_info = request.environ.get('PATH_INFO')
path_info = path_info.split('VirtualHostRoot')[-1]
query_string = request.get('QUERY_STRING')
if query_string:
query_string = '?%s' % query_string
location = server_url + path_info + query_string
return location
My questions
Is 'PATH_INFO' always available?
Is there something else I should consider?
Thanks.
Tonico
More information about the Zope
mailing list