Python code to generate html
#!C:\Python27\python.exe -u
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable()  # for troubleshooting
print "Content-type: text/html"
print
print """
<html>
<head><title>Sample CGI Script</title></head>
<body>
  <h3> Sample CGI Script </h3>
"""
form = cgi.FieldStorage()
message = form.getvalue("message", "(no message)")
print """
  <p>Previous message: %s</p>
  <p>form
  <form method="post" action="index.cgi">
    <p>message: <input type="text" name="message"/></p>
  </form>
</body>
</html>
""" % cgi.escape(message)
Source: CgiScripts - Python Wiki
#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields first_name = form.getvalue('first_name') last_name = form.getvalue('last_name') print "Content-type:text/html\r\n\r\n" print "<html>" print "<head>" print "<title>Hello - Second CGI Program</title>" print "</head>" print "<body>" print "<h2>Hello %s %s</h2>" % (first_name, last_name) print "</body>" print "</html>"


Links:
Python CGI Programming
Python CGI Programming | TutorialsPoint.com

last updated 4 Mar 2016