[Tutor] cgi.FieldStorage and dictionary.get(' ')

Luis N tegmine at gmail.com
Fri Dec 31 02:00:14 CET 2004


Hi,

I've passed this through the interperter line-by-line, yet still can't
get it to work right.

The first time the cgi driver script initiates it runs the login
function which renders a zpt. Upon submission of their vitals,  the
user is authenticated via sqlobject, and if they pass the chapters
function should run. However, what I get is zip, zilch, nada. Just a
blank page, with the query string appended to the url.

def main(form):
   if form.has_key('author') and form.has_key('password'):
      q = Users.select(AND(Users.q.author==form.get('author'),
                          Users.q.password==form.get('password')))
      if len(list(q))>0:
         chapters(author=form.get('author'))
      else:
         login(failure=True)
   else:
      login(failure=False)

Out of curiosity I wrote a simple test cgi.

#!/usr/local/bin/python

print 'Content-type: text/plain\n\n'

import cgi

form = cgi.FieldStorage()
if form.has_key('author') and form.has_key('password'):
        print form.keys()
        print form.get('author')
        print form.get('password')

Strangely, the calls to print form.get('author') and
form.get('password') don't appear in the output. Only the form.keys()
appears.

Additionally, why doesn't def main(form=cgi.FieldStorage()) work, I
tried to do it as so, thinking it more graceful, and it floundered.


More information about the Tutor mailing list