[Zope3-dev] Re: Apache rewrite rules and URLs: an experiment

Jim Fulton jim at zope.com
Thu Nov 4 09:48:56 EST 2004


Peter Mayne wrote:
> Jim Fulton wrote:
> 
>> You can then use the absolute url view to get its url. You can then
>> generate site-relative urls from that.
> 
> 
> Ah. So in my .pt I can use
> 
>       <tal:block define="
>         zach python:modules['zope.app.component.hooks'];
>         zc python:modules['zope.component']"
>       >
>         <span tal:replace="python:zc.getView(zach.getSite(), 
> 'absolute_url', request)"/>
>       </tal:block>

I'd rather not see that much python code in zpt. Frankly,
I prefer to see no Python code in zpt.

> vs
> 
>     <span tal:replace="python:request.getApplicationURL()"/>
>
> to come up with exactly the same thing. Why would I use getSite again? ;-)

Because they aren't the same.  The application url is the url of the entry point
to the Zope server.  A site may have a different URL. The root sites may contain
subsites, for example.


> If I try the above <tal:block> when I access Zope directly, it works. 
> However, if I access it via Apache, I get:
> 
> ...
>   File "C:\opt\Python23\Lib\site-packages\zope\tal\talinterpreter.py", 
> line 451, in do_insertText_tal
>     text = self.engine.evaluateText(stuff[0])
>   File 
> "C:\opt\Python23\Lib\site-packages\zope\app\pagetemplate\engine.py", 
> line 105, in evaluateText
>     return unicode(text)
>   File 
> "C:\opt\Python23\Lib\site-packages\zope\app\traversing\browser\absoluteur
> l.py", line 101, in __unicode__
>     return urllib.unquote(self.__str__()).decode('utf-8')
> AttributeError: 'unicode' object has no attribute 'decode'

That's odd.

> I'm not even going to think about why this is happening.

Suit yourself.  Someone should think about why it's happening.

> So, I'm going to stick with my original tried and true rules for linking 
> within the application:
> 
> - Use relative URLs where possible.
> - Where an absolute URL (starting with "/") is required, use
>   "request.getApplicationURL(path_only=True)" to build it.
> - Don't use URLs that start with "http://host", because it breaks local
>   copies of the page.

What do you mean by local copied?  wget can adjust absolute urls
for you.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope3-dev mailing list