attribute error: absolute_url
Hiya! I have a folder /home with the standard_html_header (DTML method) this line should include a stylesheet definition if available in a (sub)folder ... <dtml-if text_css_styles><link rel="stylesheet" type="text/css" href="<dtml-var "text_css_styles.absolute_url ()">"></dtml-if> but when I call it from a subfolder where the text_css_styles DTML Document exists I get this error message: Traceback (innermost last): File /usr/local/Zope-2.3.2/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/local/Zope-2.3.2/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/Zope-2.3.2/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook (Object: Traversable) File /usr/local/Zope-2.3.2/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/Zope-2.3.2/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: index_html) File /usr/local/Zope-2.3.2/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: index_html) File /usr/local/Zope-2.3.2/lib/python/OFS/DTMLDocument.py, line 189, in __call__ (Object: index_html) File /usr/local/Zope-2.3.2/lib/python/DocumentTemplate/DT_String.py, line 538, in __call__ (Object: index_html) File /usr/local/Zope-2.3.2/lib/python/OFS/DTMLMethod.py, line 182, in __call__ (Object: standard_html_header) File /usr/local/Zope-2.3.2/lib/python/DocumentTemplate/DT_String.py, line 538, in __call__ (Object: standard_html_header) File /usr/local/Zope-2.3.2/lib/python/DocumentTemplate/DT_Util.py, line 334, in eval (Object: text_css_styles.absolute_url ()) (Info: text_css_styles) File <string>, line 0, in ? File /usr/local/Zope-2.3.2/lib/python/DocumentTemplate/DT_Util.py, line 127, in careful_getattr AttributeError: absolute_url Zope Information: Zope Version Zope 2.3.2 (source release, python 1.5.2, linux2) Python Version 2.0 (#2, Jun 14 2001, 17:54:01) [GCC 2.95.3 20010125 (prerelease)] System Platform openbsd2 Any suggestions? tia Wolfgang
wazum-mail (wolfgang) writes:
... <dtml-if text_css_styles><link rel="stylesheet" type="text/css" href="<dtml-var "text_css_styles.absolute_url ()">"></dtml-if> ... AttributeError: absolute_url That's a nasty side effect of the caching performed by many DTML tags:
If you use "<dtml-if name=XXX ...>" (this is the explicit form of "<dtml-if XXX ...>"), then "XXX" is rendered and bound to the name "XXX". When you later access "XXX", you get the already rendered value. If "XXX" is (originally) bound to a DTML object (as in your case), then it is very likely that its rendered value is a string which (of course) does not have an "absolute_url" method. Dieter
Dieter Maurer wrote:
wazum-mail (wolfgang) writes:
... <dtml-if text_css_styles><link rel="stylesheet" type="text/css" href="<dtml-var "text_css_styles.absolute_url ()">"></dtml-if> ... AttributeError: absolute_url That's a nasty side effect of the caching performed by many DTML tags:
If you use "<dtml-if name=XXX ...>" (this is the explicit form of "<dtml-if XXX ...>"), then "XXX" is rendered and bound to the name "XXX". When you later access "XXX", you get the already rendered value.
If "XXX" is (originally) bound to a DTML object (as in your case), then it is very likely that its rendered value is a string which (of course) does not have an "absolute_url" method.
Dieter
Smells like a bug to me. IMHO caching should be entirely transparent to the top-level behavior. But alas, our world is less than perfect. I'm surprised I haven't run into this myself... -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
From: Casey Duncan <cduncan@kaivo.com> Organization: Kaivo, Inc. (www.kaivo.com) Date: Mon, 18 Jun 2001 09:53:11 -0600 To: Dieter Maurer <dieter@handshake.de> Cc: "wazum-mail (wolfgang)" <wolfgang@wazum.com>, zope@zope.org Subject: Re: [Zope] attribute error: absolute_url
Dieter Maurer wrote:
wazum-mail (wolfgang) writes:
... <dtml-if text_css_styles><link rel="stylesheet" type="text/css" href="<dtml-var "text_css_styles.absolute_url ()">"></dtml-if> ... AttributeError: absolute_url That's a nasty side effect of the caching performed by many DTML tags:
If you use "<dtml-if name=XXX ...>" (this is the explicit form of "<dtml-if XXX ...>"), then "XXX" is rendered and bound to the name "XXX". When you later access "XXX", you get the already rendered value.
If "XXX" is (originally) bound to a DTML object (as in your case), then it is very likely that its rendered value is a string which (of course) does not have an "absolute_url" method.
Dieter
Smells like a bug to me. IMHO caching should be entirely transparent to the top-level behavior. But alas, our world is less than perfect.
I'm surprised I haven't run into this myself...
I ran into this type of thing in CMF when they added a __call__ to Document.py... Here's the reply I got:
On Thu, 31 May 2001, marc lindahl wrote:
Hey, that was it!! I wonder why the behaviour changed? Some new fancy caching going on somewhere?
Believe it or not, that particular caching has been there for a long time now. It has always bothered me but I didn't know why, and now I know why. :-) This specific case could be corrected, though.
This happened because Document now has a __call__() method. It didn't before.
So what would I use for the if? Something ugly like "_.hasattr('bio')" ?
I would try <dtml-if expr="_.getitem('bio', 0)">. Ugly but it works. ZPT, which is coming along very well, is designed from the start to provide clean alternatives to expressions like that.
Shane
participants (4)
-
Casey Duncan -
Dieter Maurer -
marc lindahl -
wazum-mail (wolfgang)