The processing script

What about the script that receives the form input: respond.py? It looks like this,

# respond.py
import cgi

template = '''<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
    <title>respond.py output</title>
  </head>
  <body>
    <p>Hi %s.</p>
  </body>
</html>'''

form = cgi.FieldStorage()
print 'Content-type: text/html'
print
print template % (form['user'].value)

There's not much to see. We import the cgi module so we can have it parse the communication from the server. This is done by the line: form = cgi.FieldStorage(). Then we just insert the value of the user field of the form input into the output template using string interpolation in the last line and send the string to the client by printing it..

There are several things to note about this program and process:

The output in the browser should look something like this,

.

Still nothing to look at, but as programmers you realize that now we have input to our program, and output from it, we have all the tools we need to do anything!