CGI Help Please.

SA sarmstrong13 at mac.com
Tue Jul 9 12:21:36 EDT 2002


I've been working on a little test script so I can understand the
functionality of the cgi module when writing a python cgi script. The goal
is to redirect a page from a link o the stored value in a query string.
(ex.<a href="http://localhost/cgi-bin/test2?pageID=testtext"
title="TestFile">TestFile</a>).

 I've now managed to get my script to work part way. I got rid of the server
error I was getting by changing:
#!/usr/bin/env python

To

#!/sw/bin/python

sw/bin is the directory where my default python is located. For some reason
my Apache setup chokes on the /usr/bin/env executable.

So this fixes the server error. I then set the program to display the value
for the key "pageID", but what I get is:

The test file is:

['testtxt']
Finished!


What I would like to do now is take that dictionary value(testtxt), which is
the name of the text file I would like to use, read the text in the text
file and re-display this in a new web page. Basically what I have is a html
template file and a lot of text files. My final script will take the query
string from the href as a text file name and send that to the python cgi
script. That value will then be used to look up the textfile, read it's
data, and print the file in the body section between <pre></pre> tags on a
new web page. With this script, I will have only a template file that needs
it's links updated when I add new textfiles instead off 100+ html files
needing to be constantly maintained.

So since I'm new to python and CGI, I've been 'hacking' around on my machine
with different codes trying to understand how the script would function. Can
anyone help me please?

Below is the test script I wrote:
#!/sw/bin/python

import cgi
import re

QueryString = cgi.parse_qs('pageID=testtxt')

for pageID in QueryString.keys():
    QValue = QueryString[ pageID]
#    passvalue = [Qvalue]
#    body = open("QValue", "r")
#    for line in body.readlines():
    print "Content-Type: text/plain\n\n"
#        print line
    
    print "The test file is:\n"
    print QValue
#    body.close()
    
print "Finished!"

Any ideas on what I'm doing wrong?

Thanks.
SA


-- 
"I can do everything on my Mac I used to on my PC. Plus a lot more ..."
-Me




More information about the Python-list mailing list