Python中通过CGI传递信息

2023-11-22 0 409

CGI(Common Gateway Interface),即通用网关接口,是 WWW(World Wide Web)技术中最重要的技术之一,是外部应用程序(即 CGI 程序)与 Web 服务器之间的接口标准,负责在 CGI 程序和 Web 服务器之间传递信息。

通过CGI程序传递checkbox数据

checkbox用于提交一个或者多个选项数据,HTML代码如下:

nbsp;html>



  "utf-8">
菜鸟教程(runoob.com)


以下为 checkbox.py 文件的代码:

#!/usr/bin/python3

# 引入 CGI 处理模块
import cgi, cgitb

# 创建 FieldStorage的实例
form = cgi.FieldStorage()

# 接收字段数据
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 权限:

chmod 755 checkbox.py

通过CGI程序传递Radio数据

Radio 只向服务器传递一个数据,HTML代码如下:

nbsp;html>



  "utf-8">
菜鸟教程(runoob.com)


radiobutton.py 代码如下:

#!/usr/bin/python3

# 引入 CGI 处理模块
import cgi, cgitb

# 创建 FieldStorage的实例
form = cgi.FieldStorage()

# 接收字段数据
if form.getvalue('site'):
  site = form.getvalue('site')
else:
  site = "提交数据为空"

print ("Content-type:text/html")
print ()
print ("")
print ("")
print ("")
print ("")
print ("")
print ("")
print (" 

修改 radiobutton.py 权限:

chmod 755 radiobutton.py

通过CGI程序传递 Textarea 数据

Textarea 向服务器传递多行数据,HTML代码如下:

nbsp;html>



  "utf-8">
菜鸟教程(runoob.com)


textarea.py 代码如下:

#!/usr/bin/python3

# 引入 CGI 处理模块
import cgi, cgitb

# 创建 FieldStorage的实例
form = cgi.FieldStorage()

# 接收字段数据
if form.getvalue('textcontent'):
  text_content = form.getvalue('textcontent')
else:
  text_content = "没有内容"

print ("Content-type:text/html")
print ()
print ("")
print ("")
print ("")
print ("")
print ("")
print ("")
print (" 

修改 textarea.py 权限:

chmod 755 textarea.py

通过CGI程序传递下拉数据

HTML 下拉框代码如下:

nbsp;html>



  "utf-8">
菜鸟教程(runoob.com)


dropdown.py 代码如下所示:

#!/usr/bin/python3

# 引入 CGI 处理模块
import cgi, cgitb

# 创建 FieldStorage的实例
form = cgi.FieldStorage()

# 接收字段数据
if form.getvalue('dropdown'):
  dropdown_value = form.getvalue('dropdown')
else:
  dropdown_value = "没有内容"

本文来源:www.lxlinux.net/8072.html,若引用不当,请联系修改。

相关文章

猜你喜欢
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    文章总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 4975 +

    运行天数

你的前景,远超我们想象