windows XP系统下输入命令 python -m CGIHTTPServer不执行

来源:互联网 发布:淘宝设计团队叫什么 编辑:程序博客网 时间:2024/04/27 18:52
在windows XP系统下输入命令 python -m CGIHTTPServer  搭建了CGI服务器
测试脚本为
Python code
test.py
1
2
3
4
print "Content-Type: text/html" 
print r'<p> Hello word!'



然后输入:http://localhost:8000/test.py
得到的结果为:

print "Content-Type: text/html" 
print r'<p> Hello world!'

可见脚本并没有执行我用的Python是 Python 2.7.5

 

解决方法如下:

1.在python安装目录下建立cgi-bin文件夹

2.将test.py文件放在cgi-bin中,头与体之间要加入换行,即将print  "Content-Type: text/html" 换成print "Content-Type :text/html\n\n"

3.在cmd命令下进入python的安装目录,也可以不再安装目录下,输入python -m CGIHTTPServer搭建服务器

4.输入http://localhost:8000/cgi-bin/test.py

 

就可以看到结果如下:

Hello world!