首页 > 代码库 > Python网页编程(CGI)

Python网页编程(CGI)

1)程序简单,引用几个关键处理即可:
#coding=utf-8#!/usr/bin/python# CGI处理模块from os import environimport cgi, cgitb# 创建 FieldStorage 的实例化form = cgi.FieldStorage() # 获取数据user_id ="a";password="b";first_name = form.getvalue(‘first_name‘)last_name  = form.getvalue(‘last_name‘)en = environ.get(‘HTTP_COOKIE‘)+"";coks = en.split(‘;‘)for c in coks:    kv = c.split("=");    if(kv[0]==‘UserID‘):        user_id=kv[1];        continue    if(kv[0]==‘Password‘):        password=kv[1];   print(‘Content-type:text/html\r\n\r\n‘)print("Set-Cookie:UserID=XYZ;\r\n")print("Set-Cookie:Password=XYZ123;\r\n")print("Set-Cookie:Expires=Tuesday, 31-Dec-2007 23:12:40 GMT\";\r\n")print("Set-Cookie:Domain=www.w3cschool.cc;\r\n")print("Set-Cookie:Path=/perl;\n")print(‘<html>‘)print(‘<head>‘)print(‘<title>Hello Word - First CGI Program</title>‘)print(‘</head>‘)print(‘<body>‘)print(‘<h2>Hello Word! This is my first CGI program</h2>‘)print("<h2>Hello %s %s</h2>" % (first_name, last_name))print("User ID  = %s" % user_id)print("Password = %s" % password)print(‘</body>‘)print(‘</html>‘)


2)配置很关键(IIS7.0):
技术分享

 

3)按下面填好:

技术分享

走到这里,跟C#语言进行处理,已经无多大的区别了。Python这种脚本式用来做服务端的数据提供者还是比较好。
Python语言在很多地方,特别是类型,类等方面跟JS很类似,但没有JS复杂。
浏览了一遍,能算学到一门语言?

Python网页编程(CGI)