在 Mac OS X 上使用 CGIHTTPServer 提供 Python 脚本服务
我正在尝试在 Mac OS X 上设置 Python 的 CGIHTTPServer
以便能够在本地提供 CGI 脚本,但我似乎无法做到这一点。
我有一个简单的测试脚本:
#!/usr/bin/env python
import cgi
cgi.test()
它具有权限 -rwxr-xr-x@
,位于 ~/WWW
(具有权限 drwxr-xr- x)。它在 shell 中运行得很好,我有这个脚本可以使用 CGIHTTPServer 为它们提供服务:
import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ["~/WWW"]
PORT = 8000
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
但是当我运行它时,转到 localhost:8000 只提供脚本的内容,而不是结果(即它返回代码,而不是输出)。
我做错了什么?
I'm trying to set up Python's CGIHTTPServer
on Mac OS X to be able to serve CGI scripts locally, but I seem to be unable to do this.
I've got a simple test script:
#!/usr/bin/env python
import cgi
cgi.test()
It has permissions -rwxr-xr-x@
and is located in ~/WWW
(with permissions drwxr-xr-x
). It runs just fine from the shell and I have this script to serve them using CGIHTTPServer
:
import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ["~/WWW"]
PORT = 8000
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
But when I run it, going to localhost:8000
just serves the content of the script, not the result (i.e. it gives back the code, not the output).
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cgi_directories
中的路径与 URL 的路径部分匹配,而不是实际的文件系统路径。将其设置为["/"]
或[""]
可能效果更好。The paths in
cgi_directories
are matched against the path part of the URL, not the actual filesystem path. Setting it to["/"]
or[""]
will probably work better.