Reputation: 3572
I don't have to use os.environ
but that might be the easiest method.
I can successfully get the previous URL using:
sURL = os.getenv('HTTP_REFERER')
and the arguments of the current string using:
sURL = os.environ['QUERY_STRING']
but I cannot get the current URL.
Other answers here advise:
sURL = self.request.url
(or self.request.host) but when I do that I get:
sURL = self.request.url NameError: global name 'self' is not defined
How can I easily get the current URL?
Full code:
import os
def GetTestMode ():
sURL = self.request.url
print '<br />sURL = ' + sURL + '<br />'
Upvotes: 1
Views: 8562
Reputation: 3572
Thanks to a colleague, this can be solved with:
import os.path
sURL = os.path.realpath('.')
print 'sURL = ' + sURL + '<br />'
See os.path which says, "Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path (if they are supported by the operating system)."
So this does not return the URL but the file path, but I can also use this.
Upvotes: 1