[ZPT] path variable doesn't exist

Clemens Robbenhaar robbenhaar at espresto.com
Tue Jan 20 05:02:09 EST 2004


Hi Justin,

 > What is the easy way to get round the error generated when a path variable 
 > that doesn't exist is referred to? I'm trying to detect an optional 
 > querystring argument, but when it's not there I get an error for referring 
 > to it.

 I cannot answer the general question (however as it seems that You are
using python expressions here, 'getattr' may be your friend).

 For request variables passed via HTTP, I prefer to look them up in the
"form" attribute of the request, i.e. instead of:

 > 
 > This is the code that generates the error when one or both of cid and tid 
 > are not in the querystring.
 > 
 > <div tal:condition="python:request.cid and request.tid">
 > Only show me if cid and tid exist.
 > </div>

I would try: request.form['cid'] (which still creates an error, however)
or

   request.form.get('cid','')

(where the second argument can be omitted and defaults to "None" aka
nothing)

The "form" attribute even contains the HTTP-parameter if its not a form
posting but passed via usual '?cid=something&tid=something+different'
notation in the URL.

hope this helps,
clemens



More information about the ZPT mailing list