python - request.path 和 url_for 在 mod_wsgi 下的 Flask 中不匹配

标签 python flask mod-wsgi

在 Flask 中,有没有办法获取包含 WSGI 或其他可能添加的任何“装饰”的 request.path?

在测试模式下运行(仅在端口 5000 上),我的 request.pathurl_for('settings') 匹配得很好,但是一旦在 WSGI,不出所料,我的url_for('settings')变成了/manage/settings/,但是request.path产生 /settings/

我的 httpd.conf 中有以下内容,并且正在努力移动 application从开发到实时站点。

WSGIScriptAlias /manage /sw/servermanager/servermanager.wsgi
WSGIDaemonProcess servermgr user=user group=grp threads=4
<Directory /sw/servermanager>
    WSGIProcessGroup servermgr
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptReloading On
    Order deny,allow
    Allow from all
</Directory>

我喜欢让模板非常通用然后使用 CSS 动态显示导航信息的想法。我使用了 this answer 中提供的技术就此构建我的观点,但是当我将 mod_wsgi 添加到等式中时,问题就出现了。

我环顾了请求对象,除了可能使用 url_rule 之外,并没有看到我想要的那么多东西,但随后参数就避开了我。

为了更好的衡量,我正在使用的 WSGI 脚本的链接:https://github.com/FernFerret/servermanager/blob/master/servermanager.wsgi

我也对 request 对象的文档感兴趣,我通过使用内置调试器和 help(request) 找到了解决它的方法。

编辑:我应该说,在运行 mod_wsgi 的 Apache 下,url 不匹配。

最佳答案

这是一个特性,而不是一个错误。查看文档 for the URL-related attributes on the requestfor the request object itself .

您可能需要使用 request.script_root + request.path

关于python - request.path 和 url_for 在 mod_wsgi 下的 Flask 中不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15093593/

相关文章:

python - 如何使用 Python 日志记录收集 App Engine 请求的日志?

python - 辣椒 : Code doesn't work fine after naoqi upgrade

python - 检查外键上的对象是否已设置

python - Windows 上的 mod_wsgi WSGIPythonPath 多路径

Python 2.7 警告 : __init__ not compatible to __new__

python - 从 Flask POST 中传递的不仅仅是结果页面

python - Flask、SQLAlchemy 和多线程 : MySQL too many connections

python - Flask-Admin +(Flask-Login 和/或 Flask-Principal)

python - Mac OSX 10.5.8 上适用于 Django 的 mod_wsgi

python - 将 Django 站点放在另一个 Django 站点的子目录中