社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
AddHandler cgi-script .cgi .pl .py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Desc: python common cgi
Date: 2017-11-23
Author: xxxx
"""
import time
#定义全局变量
nowtime = ''
def initData():
"""用来获取填充html页面的数据
"""
global nowtime
nowtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
def genHtml2():
"""生成HTML页面, 使用三个双引号,使Python中的HTML页面更美观
"""
print 'Content-type:text/html'
print
print """
<html>
<head>
<meta charset="utf-8">
<title>Python CGI DEMO程序</title>
</head>
<body>
<h1>This is DEMO~~~~</h1>
</body>
</html>
"""
def genHtml():
"""生成HTML页面
"""
print "Content-type:text/html"
print
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Python CGI DEMO程序</title>'
print '</head>'
print '<body>'
print '<h2>当前时间为: %s</h2>' % nowtime
print '</body>'
print '</html>'
def main():
"""CGI入口
"""
#初始化环境
initData()
#生成页面
genHtml()
if __name__ == '__main__':
main()
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!