head.html: an HTML web page that contains a form
<form action="hat.py" method="get">
<input type="text" name="circumference" />
<input type="submit" />
</form>
hat.py: a Python program that receives the data, carries out
the calculation, and prints the result into a new web page
head_to_hat.py
if the user has not sent us any data:
output a web page containing the form
else:
calculate the person's hat size
output a web page containing the form and the hat size
Or:
set the hat size to 0
if the user has sent us some data:
calculate the person's hat size
output a web page containing the form and the hat size
head_to_hat.py: a self-processing pageComplete the program:
#!/usr/local/bin/python3
from cgitb import enable
enable()
from cgi import FieldStorage
from math import pi
print('Content-Type: text/html')
print()
form_data = FieldStorage()
hat_size = 0.0
if
print("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Big head</title>
</head>
<body>
<form action="head_to_hat.py" method="get">
<label for="circumference">Circumference: </label>
<input type="text" name="circumference" id="circumference" />
<label for="hat_size">Hat size: </label>
<input type="text" name="hat_size" id="hat_size" value = "%f" disabled />
<input type="submit" />
</form>
</body>
</html>""" % (hat_size))
head_to_hat.py to make the form a sticky form
Modify head_to_hat.py so that it also validates the user's input