PYTHON CGI 问题,跪求解答

Jacob_Emma 2015-08-25 07:07:11
开发环境 win7 python 3.4.1
同样的现象出现在 Fedora 21 python3.4.3

1 创建目录 cgi-bin, views
2 在目录 cgi-bin下面创建 main.py
3 main.py 只有两行内容

print ("Content-type:text/html \n\n")
print ("hello")

Linux 版本下多了 #!/usr/bin/python(就是我的python 目录)


4 启动python web 服务器

python -m http.server 8900
启动OK

5 但是,当我在浏览器进入 localhost:8900/cgi-bin/main.py的时候,正常应该显示 hello , 实际却显示了两行 python 源代码,说明没起作用

谁能帮我一下呢?先谢谢了

BTW:所有相关文件,文件夹,都被我 chmod 777 了
...全文
223 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ForestDB 2015-08-27
  • 打赏
  • 举报
回复
这是我在Windows下做的。

D:\codes\tmp>tree /F
Folder PATH listing for volume D
Volume serial number is 2677-DC99
D:.
└─cgi-bin
        main.py

D:\codes\tmp>type cgi-bin\main.py
print ("Content-type:text/html \n\n")
print ("hello")

D:\codes\tmp>C:\Python34\python.exe -m http.server --cgi 8000
Serving HTTP on 0.0.0.0 port 8000 ...
127.0.0.1 - - [27/Aug/2015 10:13:31] "GET /cgi-bin/main.py HTTP/1.1" 200 -
127.0.0.1 - - [27/Aug/2015 10:13:31] command: C:\Python34\python.exe -u D:\codes
\tmp\cgi-bin\main.py ""
127.0.0.1 - - [27/Aug/2015 10:13:31] CGI script exited OK

http://localhost:8000/cgi-bin/main.py

Jacob_Emma 2015-08-26
  • 打赏
  • 举报
回复
引用 3 楼 ForestDB 的回复:
python -m http.server --cgi 8000 Python 3我不是特别熟,上面是在文档中找到的。
非常感谢您的回答 可是还是不行 您还能再帮我看看吗?谢谢了
ForestDB 2015-08-26
  • 打赏
  • 举报
回复
python -m http.server --cgi 8000 Python 3我不是特别熟,上面是在文档中找到的。
Jacob_Emma 2015-08-25
  • 打赏
  • 举报
回复
引用 1 楼 ForestDB 的回复:
#!/usr/bin/python这句呢?
这句有 在我Linux下有 Windows版本下没有
ForestDB 2015-08-25
  • 打赏
  • 举报
回复
#!/usr/bin/python这句呢?

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧