Hi, I'm doing a back link to go on a page (yes, I know browsers have back buttons, but some people don't like to use them ;-) which is easy enough: <A href="<dtml-var "REQUEST.environ['HTTP_REFERER']">">Back</A> except that if there is no referer, you get a key error. So I thought I'd try the following: <A href="<dtml-var "REQUEST.environ['HTTP_REFERER']" missing='/'>">Back</A> But I still get a key error. I thought the 'missing' attribute was supposed to catch that? Chris
On Wed, Mar 29, 2000 at 05:42:55PM +0100, Chris Withers wrote:
I'm doing a back link to go on a page (yes, I know browsers have back buttons, but some people don't like to use them ;-) which is easy enough:
<A href="<dtml-var "REQUEST.environ['HTTP_REFERER']">">Back</A>
except that if there is no referer, you get a key error. So I thought I'd try the following:
<A href="<dtml-var "REQUEST.environ['HTTP_REFERER']" missing='/'>">Back</A>
But I still get a key error. I thought the 'missing' attribute was supposed to catch that?
Not quite. You are tripping a key error here so that won't work. Try: <dtml-if "REQUEST.has_key('HTTP_REFERER')"> <dtml-var "REQUEST['HTTP_REFERER']"> </dtml-if> -Petru
Not quite. You are tripping a key error here so that won't work. Try:
Sorry to be picky here but, quoting from Table 15 on page 21 of the DTML Guide: missing - Provide a value to be used if the ariable(sic) is missing, rather than raising a KeyError.
<dtml-if "REQUEST.has_key('HTTP_REFERER')"> <dtml-var "REQUEST['HTTP_REFERER']"> </dtml-if>
This is what I ended up doing :-) Is it just me or does it seem silly that: <dtml-var HTTP_REFERER missing='/'> works as expected but <dtml-var "REQUEST.environ['HTTP_REFERER']" missing='/'> doesn't, even though they're logically the same thing? The KeyError should be caught when evaluating the expression as well as the name in dtml-var :( I might chuck this in the collector at some stage... Chris
Hi Chris, Chris Withers wrote:
Hi,
I'm doing a back link to go on a page (yes, I know browsers have back buttons, but some people don't like to use them ;-) which is easy enough:
<A href="<dtml-var "REQUEST.environ['HTTP_REFERER']">">Back</A>
except that if there is no referer, you get a key error. So I thought I'd try the following:
<A href="<dtml-var "REQUEST.environ['HTTP_REFERER']" missing='/'>">Back</A>
But I still get a key error. I thought the 'missing' attribute was supposed to catch that?
This counts only for something like <dtml-var ought_to_be_missing missing> In your case you are inside Python when calling with " ". So "missing" cannot catch this exception. (Actually this simple <dtml-var .. > does much magic :) So in your case you should do: <dtml-if "REQUEST.environ.has_key('HTTP_REFERER')"> <A href="<dtml-var "REQUEST.environ['HTTP_REFERER']">">Back</A> </dtml-if> This has the advantage of no blind link if there is no HTTP_REFERER set. Hth Tino Wildenhain
hi again, Chris Withers wrote:
Hi,
I'm doing a back link to go on a page (yes, I know browsers have back buttons, but some people don't like to use them ;-) which is easy enough:
<A href="<dtml-var "REQUEST.environ['HTTP_REFERER']">">Back</A>
except that if there is no referer, you get a key error. So I thought I'd try the following:
<A href="<dtml-var "REQUEST.environ['HTTP_REFERER']" missing='/'>">Back</A>
But I still get a key error. I thought the 'missing' attribute was supposed to catch that?
Btw. this works: <dtml-with REQUEST> <dtml-with environ> <dtml-var HTTP_REFERER missing> </dtml-with> </dtml-with> or <dtml-with "REQUEST.environ"> <dtml-var HTTP_REFERER missing> </dtml-with> if you want :-) Regards, Tino Wildenhain
participants (3)
-
Chris Withers -
Petru Paler -
Tino Wildenhain