[Zope3-dev] Re: Apache rewrite rules and URLs: an experiment
Peter Mayne
PeterMayne at ap.spherion.com
Wed Nov 3 21:41:04 EST 2004
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>
vs
<span tal:replace="python:request.getApplicationURL()"/>
to come up with exactly the same thing. Why would I use getSite again? ;-)
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'
I'm not even going to think about why this is 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. Unfortunately, all of the Zopeish ways of
generating URLs that I've seen so far break this rule.
(An example of building an absolute URL:
<a tal:attributes="href
python:'%s/sitemap.html'%request.getApplicationURL(path_only=True)">
Site Map
</a>
)
If anyone can come up with some better rules, I'd love to hear them.
Stephan, I think it would be highly useful to mention at least the first
two rules in chapter 4: if people hardcode the wrong URLs, their
applications will break when they first start testing behind Apache.
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