windows下 python 自带的CGIHTTPServer使用

来源:互联网 发布:ubuntu安装分区设置 编辑:程序博客网 时间:2024/05/17 09:05

利用python自带的CGIHTTPServer服务器搭建一个简单的查看本机信息的服务。
python2.7
windows

  • 创建目录www,在该目录下创建cgi-bin文件夹;
  • 在cgi-bin目录下创建python文件,命名为test.py,如图1;
  • 启动python自带的CGIHTTPServer,命令为:python2.exe -m CGIHTTPServer 8811,如图2;
  • 访问路径http://localhost:8811/cgi-bin/test.py,即可看到本机信息。图3.
    图1,
    这里写图片描述
    test.py内容如下:
# -*- coding: UTF-8 -*-# filename:test.pyimport osprint "Content-type: text/html"printprint "<meta charset=\"utf-8\">"print "<b>环境变量</b><br>";print "<ul>"for key in os.environ.keys():    print "<li><span style='color:green'>%30s </span> : %s </li>" % (key,os.environ[key])print "</ul>"

图2,启动内置CGIHTTPServer ,指定端口为8811
这里写图片描述
图3,本机信息如下:
这里写图片描述

0 0
原创粉丝点击