.htaccess和python脚本

2024-09-26 18:08:13 发布

您现在位置:Python中文网/ 问答频道 /正文

n00b问题。 我有一个.htaccess文件,其中包含以下内容:

AddHandler python-program .py
PythonHandler index

我试图编写另一个名为script2.py的程序,但当我键入它fileserver/script2.py时,它会重定向到fileserver/index.py。有什么办法阻止这一切吗?


Tags: 文件py程序index键入program重定向办法
1条回答
网友
1楼 · 发布于 2024-09-26 18:08:13

配置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.

相关问题 更多 >

    热门问题