> 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
I'm not sure what a zpt is, but it sounds like the form to request the vitals,
so that's a
start. :)
> 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.
First off, make sure that you have the "Content-Type: text/html\n\n"
line print before anything else whenever you send output to the web.
Presumably it worked for the form display, but you have to keep resending it
each time
the page changes.
> 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)
Without seeing the def for login(failure), and not being familiar with SQL,
I'll take a pass
on these lines, but I am curious why you declare failure as true or false in
the login
function?
>
> 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')
Instead of form.get(), try this:
print form['author'].value
print form['password'].value
Working with cgi scripts is always a bit tricky because of the added variable
of the server
displaying the page, so I define this little function on anything I am working
on:
from sys import stderr # Unix only!
def s(msg):
s = stderr.write # Sends messages to the error log via s()
s(msg + '\n') # adds a carriage return :)
Someone else more versed than I could probably tell you if there is a windows
equivalent, but what I do is open another shell and tail -f the error log while
I test the
script. Any errors or tracebacks appear there anyway, and I can add little
notes between
functions to see where the thing breaks down. Especially handy to
"pre-display" the
expected output to make sure I get what I expect, and its not the web server
that's eating
the result or something.
>
> 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.
I am not sure about this, but I've always put the form = cgi.Fieldstorage in
the global
namespace so I could get at it with subsequent functions.
I am guessing that your version didn't work because the form namespace isnt
getting
filled with cgi.Fieldstorage --before-- the function is defined. Remember
python tries to
look through all the defs and make sure they are syntactically correct before
actually
running the script. You probably got an AttributeError, right?
Patric
OBTW... the .value method might be superceded by newer versions of python. I
am not
well versed on all the changes in 2.4 yet. :)
> _______________________________________________ Tutor maillist -
> [email protected] http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor