当我在 shell 中运行 python -m SimpleHTTPServer 8000
或 python -m CGIHTTPServer 8000
时,我将当前目录的内容托管到互联网。
当我浏览到 192.xxx.x.xx:8000/cgi_script.py
时,我想在命令行中使用上述命令使以下 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 以及我托管它的文件夹。
最佳答案
尝试使用 python -m CGIHTTPServer 8000
。
请注意,您必须将脚本移动到 cgi-bin
或 htbin
目录才能运行。
关于python - 如何使用 `python -m SimpleHTTPServer 8000` 或 `python -m CGIHTTPServer 8000` 托管 python cgi 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793133/