新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Python中通過(guò)CGI傳遞信息
CGI(Common Gateway Interface),即通用網(wǎng)關(guān)接口,是 WWW(World Wide Web)技術(shù)中最重要的技術(shù)之一,是外部應(yīng)用程序(即 CGI 程序)與 Web 服務(wù)器之間的接口標(biāo)準(zhǔn),負(fù)責(zé)在 CGI 程序和 Web 服務(wù)器之間傳遞信息。

通過(guò)CGI程序傳遞checkbox數(shù)據(jù)
checkbox用于提交一個(gè)或者多個(gè)選項(xiàng)數(shù)據(jù),HTML代碼如下:
nbsp;html>
"utf-8">
菜鳥(niǎo)教程(runoob.com)
"/cgi-bin/checkbox.py" method=
"POST" target=
"_blank">
type=
"checkbox" name=
"runoob" value=
"on" /> 菜鳥(niǎo)教程
type=
"checkbox" name=
"google" value=
"on" /> Google
type=
"submit" value=
"選擇站點(diǎn)" />
以下為 checkbox.py 文件的代碼:
#!/usr/bin/python3
# 引入 CGI 處理模塊
import cgi, cgitb
# 創(chuàng)建 FieldStorage的實(shí)例
form = cgi.FieldStorage()
# 接收字段數(shù)據(jù)
if form.getvalue('google'):
google_flag = "是"
else:
google_flag = "否"
if form.getvalue('runoob'):
runoob_flag = "是"
else:
runoob_flag = "否"
print ("Content-type:text/html")
print ()
print ("")print ("")
print ("")
print ("")
print ("")print ("")
print ("
修改 checkbox.py 權(quán)限:
chmod 755 checkbox.py
通過(guò)CGI程序傳遞Radio數(shù)據(jù)
Radio 只向服務(wù)器傳遞一個(gè)數(shù)據(jù),HTML代碼如下:
nbsp;html>
"utf-8">
菜鳥(niǎo)教程(runoob.com)
"/cgi-bin/radiobutton.py" method=
"post" target=
"_blank">
type=
"radio" name=
"site" value=
"runoob" /> 菜鳥(niǎo)教程
type=
"radio" name=
"site" value=
"google" /> Google
type=
"submit" value=
"提交" />
radiobutton.py 代碼如下:
#!/usr/bin/python3
# 引入 CGI 處理模塊
import cgi, cgitb
# 創(chuàng)建 FieldStorage的實(shí)例
form = cgi.FieldStorage()
# 接收字段數(shù)據(jù)
if form.getvalue('site'):
site = form.getvalue('site')
else:
site = "提交數(shù)據(jù)為空"
print ("Content-type:text/html")
print ()
print ("")
print ("")
print ("")
print ("")
print ("")
print ("")
print ("
修改 radiobutton.py 權(quán)限:
chmod 755 radiobutton.py
通過(guò)CGI程序傳遞 Textarea 數(shù)據(jù)
Textarea 向服務(wù)器傳遞多行數(shù)據(jù),HTML代碼如下:
nbsp;html>
"utf-8">
菜鳥(niǎo)教程(runoob.com)
"/cgi-bin/textarea.py" method=
"post" target=
"_blank">
"textcontent" cols="40" rows="4">
在這里輸入內(nèi)容...
type=
"submit" value=
"提交" />
textarea.py 代碼如下:
#!/usr/bin/python3
# 引入 CGI 處理模塊
import cgi, cgitb
# 創(chuàng)建 FieldStorage的實(shí)例
form = cgi.FieldStorage()
# 接收字段數(shù)據(jù)
if form.getvalue('textcontent'):
text_content = form.getvalue('textcontent')
else:
text_content = "沒(méi)有內(nèi)容"
print ("Content-type:text/html")
print ()
print ("")
print ("")
print ("")
print ("")
print ("")
print ("")
print ("
修改 textarea.py 權(quán)限:
chmod 755 textarea.py
通過(guò)CGI程序傳遞下拉數(shù)據(jù)
HTML 下拉框代碼如下:
nbsp;html>
"utf-8">
菜鳥(niǎo)教程(runoob.com)
"/cgi-bin/dropdown.py" method=
"post" target=
"_blank">
"dropdown"> "runoob" selected>菜鳥(niǎo)教程"google">Google
type=
"submit" value=
"提交"/>
dropdown.py 代碼如下所示:
#!/usr/bin/python3
# 引入 CGI 處理模塊
import cgi, cgitb
# 創(chuàng)建 FieldStorage的實(shí)例
form = cgi.FieldStorage()
# 接收字段數(shù)據(jù)
if form.getvalue('dropdown'):
dropdown_value = form.getvalue('dropdown')
else:
dropdown_value = "沒(méi)有內(nèi)容"
分享文章:Python中通過(guò)CGI傳遞信息
當(dāng)前鏈接:http://www.dlmjj.cn/article/djhceeh.html


咨詢(xún)
建站咨詢(xún)
