Hallo,
Tracy S.Ruggles hat gesagt: // Tracy S.Ruggles wrote:
> I have ExtraPathInfo turned on in my Application.config file and,
> currently, to get the actual URL of the current servlet I have to do
> something like this:
>
> class MyPage(Page):
> def awake (self, transaction):
> Page.awake (self, transaction)
> self.extraURLItems =
> self.request().extraURLPath().split('/')[1:]
> self.servletPath = '%s/%s/%s' % (
> # the name apache uses to redirect to webkit:
> self.request().servletPath(),
> # the name of the context:
> self.request().pathInfo().split('/')[0],
> # the name of this servlet:
> self.request().servletPathFromSiteRoot().split('/')[0],
> # alternately, the last item could just be:
> # self.__class__.name
> )
>
> This would mean that http://127.0.0.1/WK/Context1/MyPage/Item/200 would
> produce servletPath = '/WK/Context1/MyPage'.
>
> The bottom line is: I need to get the absolute URL to prefix all links
> produced by 'MyPage' since relative URLs just add onto the URL such that
> <a href="OtherItem/400">400</a> is interpreted as:
> 'http://127.0.0.1/WK/Context1/MyPage/Item/OtherItem/400', and
> <a href="/OtherItem/400">400</a> is interpreted as:
> 'http://127.0.0.1/OtherItem/400'.
>
> I could always do this: <a href="../OtherItem/400"> but it doesn't seem
> intuitive. I'd rather have '''<a href="%s/OtherItem/400">''' %
> self.servletPath
>
> Is there a better/simpler way to get at it than this?
I don't know, if it's simpler, but I use this SitePage method a lot:
def getServletRoot(self):
req = self.request()
context = req.contextName()
adapter = req.adapterName()
return "/".join([adapter, context])
which even gives the correct absolute patch on
http://host/~user/cgi-bin/wk.cgi/theContext
pages.
It's used like
"""<a href="%s/path/to/servlet.py">""" % self.getServletRoot()
and results in
<a href="/~user/cgi-bin/wk.cgi/theContext/path/to/servlet.py">
ciao
--
Frank Barknecht _ ______footils.org__
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss