HTML表单POST到Python脚本? [英] HTML form POST to a python script?
本文介绍了HTML表单POST到Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道有关如何将数据从HTML表单转换为python脚本的任何良好资源? p>对于非常基本的 CGI 脚本,您可以使用 cgi模块。查看Python文档中的以下文章,了解如何处理通过 POST
提交的HTML表单:
上述文章中的示例:
# !/ usr / bin / env python
import cgi
import cgitb; cgitb.enable()#用于排除故障
printContent-type:text / html
print
$ b print
< html> ;
< head>< title>示例CGI脚本< / title>< / head>
< body>
< ; h3> Sample CGI Script< / h3>
form = cgi.FieldStorage()
message = form.getvalue(message,(no )
print
< form method =postaction =index.cgi>
< p>消息:< input type =textname =message/> ;< / p>
< / form>
< / body>
< / html>
Does anyone know of any good resources for information on how to POST data from a HTML form over to a python script?
解决方案
For a very basic CGI script, you can use the cgi module. Check out the following article from the Python documentation for a very basic example on how to handle an HTML form submitted through POST
:
Example from the above article:
#!/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
这篇关于HTML表单POST到Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文