[Tutor] CGI/Python

Jason Drake jdrake@jam.rr.com
Sun, 28 Jan 2001 21:13:12 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_006D_01C0896F.1F17C300
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Okay... I'm still battling with this and am currently fighting with the =
example as given in the 'Support module for CGI (Common Gateway =
Interface) scripts.' at the Python.org website. I am very near playing =
cut'n'paste with this along with some information I know from my =
previous forays into this langauge. At present my code looks like this:

#!/usr/bin/python
#
# cheezy2.cgi
#
=20
import cgi
=20

print "Content-type: text/html\n"
=20
form =3D cgi.FieldStorage()
form_ok =3D 0
if form.has_key("name") and form.has_key("addr"):
    form_ok =3D 1
if not form_ok:
    print "<H1>Error</H1>"
    print "Please fill in the name and addr fields."
    return
print form["name"].value
print form["addr"].value

This code, coupled with a simple HTML Form using the post method =
provides me with a basic "you're an idiot" error message from my web =
server. I'm sitting here whistling "Always look on the bright side of =
life" while considering the average velocity of an unladen PC as it =
falls out a 2nd story window. Any help in explaining why this code just =
doesn't want to work, and better yet, good info on how to actually =
retrieve specific data from forms would be most appreciated at this =
junction so that I can get on with the 'harder' aspects of what I will =
do with the data once I can get it into my grubby lil hands. :)

Jason

------=_NextPart_000_006D_01C0896F.1F17C300
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Okay... I'm still battling with this =
and am=20
currently fighting with the example as given in the <FONT face=3D"Times =
New Roman"=20
size=3D3>'Support module for CGI (Common Gateway Interface) scripts.' at =
the=20
Python.org website. I am very near playing cut'n'paste with this along =
with some=20
information I know from my previous forays into this langauge. At =
present my=20
code looks like this:</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/bin/python<BR>#<BR>#=20
cheezy2.cgi<BR>#<BR>&nbsp;<BR>import cgi<BR>&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>print "Content-type: =
text/html\n"<BR>&nbsp;<BR>form=20
=3D cgi.FieldStorage()<BR>form_ok =3D 0<BR>if form.has_key("name") and=20
form.has_key("addr"):<BR>&nbsp;&nbsp;&nbsp; form_ok =3D 1<BR>if not=20
form_ok:<BR>&nbsp;&nbsp;&nbsp; print=20
"&lt;H1&gt;Error&lt;/H1&gt;"<BR>&nbsp;&nbsp;&nbsp; print "Please fill in =
the=20
name and addr fields."<BR>&nbsp;&nbsp;&nbsp; return<BR>print=20
form["name"].value<BR>print form["addr"].value<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>This code, coupled with a simple HTML =
Form using=20
the post method provides me with a basic "you're an idiot" error message =
from my=20
web server. I'm sitting here whistling "Always look on the bright side =
of life"=20
while considering the average velocity of an unladen PC as it falls out =
a 2nd=20
story window. Any help in explaining why this code just doesn't want to =
work,=20
and better yet, good info on how to actually retrieve specific data from =
forms=20
would be most appreciated at this junction so that I can get on with the =

'harder' aspects of what I will do with the data once I can get it into =
my=20
grubby lil hands. :)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jason</DIV></FONT></BODY></HTML>

------=_NextPart_000_006D_01C0896F.1F17C300--