python - .htaccess 与 python 脚本

标签 python apache .htaccess web-applications

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/

相关文章:

linux - Docker 运行退出 1 httpd

php - 提交简单的 PHP 表单时出现禁止错误

apache - .htaccess HTTPS 主域并在附加域上强制使用 HTTP

python - 实例化一个新对象更好,还是简单地更新新数据的属性更好?

python - 在 matplotlib/python 中绘制多条曲线

apache - Apache 上的 Angular 2 |搜索引擎爬虫

php - 无法从命令行访问 phpmyadmin

apache - 错误文档中的内容类型

python - While 在服务器和客户端之间循环 (Python)

python - 如何在运行方法中没有循环的情况下终止 Python 中的线程?