1#!/usr/bin/env python
2# save as cgi-bin/index.py
3# Python 2.7
4import cgi
5import cgitb; cgitb.enable()
6
7form = cgi.FieldStorage()
8html = """
9<html>
10<head>
11</head>
12<body>
13<form action="index.py" name="myform" method="GET">
14 Enter length: <input type="text" name="length"><br />
15 Enter width: <input type="text" name="width"><br />
16 <input type="submit" value="submit">
17</form>
18</body>
19</html>
20"""
21
22
23try:
24 length = int(form['length'].value)
25 width = int(form['width'].value)
26 area = length * width
27 print "Content-Type: text/html"
28 print
29 print "<p>The area is: " + str(area) + "</p>"
30except KeyError:
31 print html
32