【问题标题】:URLs in mod_python Not Working as Expectedmod_python 中的 URL 未按预期工作
【发布时间】:2011-06-19 17:09:36
【问题描述】:

我正在用 apache 和 mod_python 构建一个 Web 服务器。我已经创建了 index.py,就像我看到其他人所做的那样,但与其他人不同的是,如果不将 .py 添加到 url,我将无法访问网页。

例如,http://127.0.1.1/commentsubmit 产生 404,但 http://127.0.1.1/commentsubmit.py 按预期显示页面。

一切都在我的 index.py 中,http://127.0.1.1/ 可以正常运行,但没有 .py 就没有别的了。我的其他方法如下所示:

def commentsubmit(req):
    rest of method

我很确定问题出在 mod_python 上,但我不知道是什么。是否有某种配置设置可以做到这一点? from mod_python import apache 以外的东西我应该导入吗?

【问题讨论】:

    标签: python apache url mod-python


    【解决方案1】:

    您的 apache 服务器将被配置为将请求以 .py 结尾的文件名传递给 mod_python(如果该文件存在于目录中。)

    有许多不同的解决方案可以将 /cmetsubmit 的请求传递给您的 cmetsubmit.py 处理程序。最简单的可能是使用mod_rewrite。将此添加给您.htaacess

    RewriteEngine On
    RewriteOptions Inherit
    RewriteRule   ^commentsubmit$  commentsubmit.py
    

    这是一种过时的做事方式。我重新开始您查看pyramid(或 pylons,或 django,或其他数百万个 wsgi 框架之一。)然后您可以更好地控制如何将 ulrs 映射到代码,使用基于路由的 url 调度或基于横向网址调度。

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 1970-01-01
      • 2015-02-03
      相关资源
      最近更新 更多