十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
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ù)器之間傳遞信息。

checkbox用于提交一個(gè)或者多個(gè)選項(xiàng)數(shù)據(jù),HTML代碼如下:
nbsp;html>
"utf-8">
菜鳥教程(runoob.com)
"/cgi-bin/checkbox.py" method=
"POST" target=
"_blank">
type=
"checkbox" name=
"runoob" value=
"on" /> 菜鳥教程
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
Radio 只向服務(wù)器傳遞一個(gè)數(shù)據(jù),HTML代碼如下:
nbsp;html>
"utf-8">
菜鳥教程(runoob.com)
"/cgi-bin/radiobutton.py" method=
"post" target=
"_blank">
type=
"radio" name=
"site" value=
"runoob" /> 菜鳥教程
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
Textarea 向服務(wù)器傳遞多行數(shù)據(jù),HTML代碼如下:
nbsp;html>
"utf-8">
菜鳥教程(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 = "沒有內(nèi)容"
print ("Content-type:text/html")
print ()
print ("")
print ("")
print ("")
print ("")
print ("")
print ("")
print ("
修改 textarea.py 權(quán)限:
chmod 755 textarea.py
HTML 下拉框代碼如下:
nbsp;html>
"utf-8">
菜鳥教程(runoob.com)
"/cgi-bin/dropdown.py" method=
"post" target=
"_blank">
"dropdown"> "runoob" selected>菜鳥教程"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 = "沒有內(nèi)容"