Mega Code Archive

 
Categories / Python Tutorial / CGI Web
 

Creating Self-Posting CGI Scripts

import cgi, os, sys sys.stderr = sys.stdout data = cgi.FieldStorage() formText = """Content-type: text/html\n <title>CGI Self-Post Form</title>\n <h2>Enter Quote</h2><Paragraph> <form method="POST" action="cgi_selfpost.cgi">     Name <input type="TEXT" name="name">     <paragraph>     Quote <input type="TEXT" name="quote" size="80">     <paragraph>     <input type="SUBMIT" value="send"> </form> <hr> <h2>Received Quotes</h2><paragraph>""" print formText if data.has_key('name') and data.has_key('quote'):     f = open("quotes.dat", 'a')     f.write("<li><b>%s:</b> %s</li>\n" % \             (data['name'].value, data['quote'].value))     f.close() f=open("quotes.dat", 'r') if f:     print f.read()     f.close()