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

Peter Mayne PeterMayne at ap.spherion.com
Thu Nov 4 18:27:34 EST 2004


Jim Fulton wrote:
> 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.

I agree: this is just a demonstration. :-) On the other hand, sometimes 
pragmatism wins over theory, and the occasional one-liner slips in: 
nothing like the above, though.

>> 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.

Yep, I haven't taken subsites into account. I'll have another test session.

I'm afraid "the url of the entry point to the Zope server" doesn't mean 
anything to me right now, but it'll probably become clear after some 
more experiments.

>> 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.

I agree, but that someone isn't me. I'm currently writing a Zope 3 
application, and as much as I'd like to, I just don't have time. 
Besides, judging from the ensuing conversation, you're well ahead of me 
anyway.

>> 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.

I had a quick look through the wget man page before I wrote that: 
obviously too quick. :-) How do tell wget to adjust absolute URLs?

It's worse than I thought: I just tried downloading my test page with 
Firefix, and it adjusts all of the URLs to include "http://host". I give 
up on that one.

PJDM
-- 
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"I'm after rebellion, I'll settle for lies" - Blue Oyster Cult



More information about the Zope3-dev mailing list