对于非常基本的CGI脚本,您可以使用cgi模块.查看Python文档中的以下文章,了解如何处理通过POST以下方式提交的HTML表单的基本示例:
以上文章的例子:
#!/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>
""" % message
Run Code Online (Sandbox Code Playgroud)