text files and CGI

R Heaps 1stv at srv.net
Tue Oct 17 01:02:39 EDT 2000


I am trying to learn some CGI skill with Python. This is an example I
got off the net (with a few additions). I want to write a simple program
to open a text file, parse it, and pass the information on as an HTML
file. Everything seems to work fine when checked in a terminal window,
but no text seems to come over to the browser once it gets to the opened
text file. The browser only shows the line "this is the start", but
nothing after it. The script output when run from the terminal window
looks like a normal html file should. What is going on?

***  Python script  ***

#!/usr/bin/python
#

import sys, cgi

def_dict = {'name': 'J.Q. Studmire', 'feature': 'long nose', 'month':
'April', 'year': '2000', 'closing': 'Very truly yours'}

def basic():
    print "Content-Type: text/html\n\n"
    print "<HTML><BODY>"
    print "<H3>this is the start</H3>"
    templ = open("../template.txt").read()
    test = cgi.escape(templ%(def_dict))
    print '<pre><font color="red">', test, '</font></pre>'
    print "<H3>This is the end</H3>"
    print "</BODY></HTML>"

basic()



***  text File  ***


<pre>
Dear %(name)s,
 We really like your %(feature)s, and have awarded
you the %(feature)s-of-the-month award for %(month)s %(year)s.
>From all of us here at ACMW Awards, Congradulations!
      %(closing)s,
      Dave Mitchell
<pre>








More information about the Python-list mailing list