[Tutor] CGI Help
Timothy M. Brauch
tbrauch@mindless.com
Mon Apr 7 23:08:02 2003
I'm trying to start (re)learning a little cgi programming with python. Three years
ago in a class, I wrote a very simple html page and script. I uploaded it to my
server space at school and all worked fine. Now, I am out of school and running my
own RHL 8.0 Linux box with Apache. I tried putting the files on my box but it doesn't
want to work.
Here is what I have:
-----simple.html-----
<body bgcolor="maroon">
<font color="cyan">
<h1>
<form method="post" action="simple2.py">
<input type="text" size=40 name="email" value="Type email here"><br>
Enter your password: <input type="password" size=40 name="password"><br>
Are you: <input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female<br><br>
Check any interests: <br> <input type="checkbox" name="int1" value="csc"> Computer
Science
<br><input type="checkbox" name="int2" value="skiing"> Skiing
<br><input type="checkbox" name="int3" value="kayaking"> Kayaking<br>
<br><input type="submit" value="Send It!"><input type="reset">
</form>
</h1>
----------
I know, it is bad HTML, but I was young and ignorant.
-----simple2.py-----
#!/usr/bin/python
import cgi
import smtplib
print "Content-type: text/html\n"
form=cgi.FieldStorage()
#cgi.print_form(form)
email=''
if form.has_key('email'):
email=form['email'].value
print "Your email address is", email, "<br>"
gender=''
if form.has_key('gender'):
gender=form['gender'].value
print "You are", gender, "<br>"
int1=''
if form.has_key('int1'):
int1=form['int1'].value
print "You enjoy", int1, "<br>"
int2=''
if form.has_key('int2'):
int2=form['int2'].value
print "You enjoy", int2, "<br>"
int3=''
if form.has_key('int3'):
int3=form['int3'].value
print "You enjoy", int3, "<br>"
smtp_object=smtplib.SMTP('localhost')
from_address='tbrauch@localhost'
to_addresses=['tbrauch@localhost']
message="""Subject: Form results
Here are your form results!
I am """+gender+""". I enjoy"""+int1+int2+int3+"""."""
print smtp_object.sendmail(from_address,to_addresses,message)
----------
Again, ugly coding, but like I said, I was ignorant. And, three years ago, it worked.
I got an A on this lab assignment, so it must have worked.
Here are the permissions I have set:
[root@linux0 simple]# dir
total 28
-rw-r-xr-x 1 root root 978 Apr 7 23:05 simple2.py
-rw-r--r-- 1 root root 676 Apr 7 22:48 simple.html
-rw-r-xr-x 1 root root 628 Apr 7 22:48 simple.py
The problem I get is when I click "Send It!" on the simple.html webpage, I get to look
at my simple2.py code, but it does not execute. Any ideas what I might be doing
wrong?
- Tim