如何使用`python -m SimpleHTTPServer 8000`或`python -m CGIHTTPServer 8000`托管python cgi脚本? [英] How to host python cgi script with `python -m SimpleHTTPServer 8000` or `python -m CGIHTTPServer 8000`?

查看:106
本文介绍了如何使用`python -m SimpleHTTPServer 8000`或`python -m CGIHTTPServer 8000`托管python cgi脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在shell中运行python -m SimpleHTTPServer 8000python -m CGIHTTPServer 8000时,我会将当前目录的内容托管到Internet.

When I run python -m SimpleHTTPServer 8000 or python -m CGIHTTPServer 8000 in my shell I am hosting the content of my current directory to the internet.

当我浏览到192.xxx.x.xx:8000/cgi_script.py

#!/usr/bin/env python
print "Content-Type: text/html"
print
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""

但是此脚本按原样显示,而不仅是"Hello World!".部分. 顺便说一句,我将cgi_script.py以及我托管它的文件夹的文件权限更改为755.

But this script is displayed literally and not only the "Hello World!" part. Btw I changed the file permissions to 755 for cgi_script.py as well as the folder I am hosting it from.

推荐答案

尝试使用python -m CGIHTTPServer 8000.

请注意,必须将脚本移至cgi-binhtbin目录才能运行.

Note that you have to move the script to a cgi-bin or htbin directory in order to be runnable.

这篇关于如何使用`python -m SimpleHTTPServer 8000`或`python -m CGIHTTPServer 8000`托管python cgi脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆