n00b 问题。 我有一个包含以下内容的 .htaccess 文件:
AddHandler python-program .py
PythonHandler index
我尝试编写另一个名为 script2.py 的程序,但是当我输入 fileserver/script2.py 时,它会重定向到 fileserver/index.py。有什么办法可以阻止这种情况?
最佳答案
配置 mod_python 有不同的方法。我想你想要python.publisher .文档显示此配置:
AddHandler python-program .py
PythonHandler mod_python.publisher
然后,对于您的示例,script2.py 将具有如下内容:
def index(req):
# Your handler here
请注意,文档说:
This handler allows access to functions and variables within a module via URL's.
文档提供了这个示例(我已更改为使用 script2.py):
def say(req, what="NOTHING"):
return "I am saying %s" % what
A URL http://www.mysite.com/script2.py/say would return "I am saying NOTHING". A URL http://www.mysite.com/hello.py/say?what=hello would return "I am saying hello".
通常您不想公开每个函数和变量。
The traversal will stop and HTTP_NOTFOUND will be returned to the client if:
- Any of the traversed object's names begin with an underscore ("_"). Use underscores to protect objects that should not be accessible from the web.
关于python - .htaccess 与 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14912499/