如何将文本区域数据传递给 Python CGI 脚本?
将文本区域数据传递给 CGI 程序
当需要将多行文本传递给 CGI 程序时,便会使用 TEXTAREA 元素。
以下是一个包含 TEXTAREA 框的表单的 HTML 代码示例 −
<form action = "/cgi-bin/textarea.py" method = "post" target = "_blank"> <textarea name = "textcontent" cols = "40" rows = "4"> Type your text here... </textarea> <input type = "submit" value = "Submit" /> </form>
此代码的结果如下所示 −
Type your text here... Submit
以下是 textarea.cgi 脚本,用于处理 Web 浏览器提供输入 −
#!/usr/bin/python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
if form.getvalue('textcontent'):
text_content = form.getvalue('textcontent')
else:
text_content = "Not entered"
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>";
print "<title>Text Area - Fifth CGI Program</title>"
print "</head>"
print "<body>"
print "<h2> Entered Text Content is %s</h2>" % text_content
print "</body>"
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP