首先配置Apache服务器可处理Python程序,详见:https://www.cnblogs.com/tywusy/p/15862481.html
HTML文件:index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>try it</title>
</head>
<body>
<form action="try.py" method="get">
<p>name <input type="text" name="fname" /></p>
<input type="submit" value="Submit" />
</form>
</body>
</html>
Python:try.py
#!C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe
import cgi
form = cgi.FieldStorage()
fn = form.getvalue('fname')
print("Content-type:text/html")
print()
print(fn)