在 Flask 中,有没有办法获取包含 WSGI
或其他可能添加的任何“装饰”的 request.path?
在测试模式下运行(仅在端口 5000 上),我的 request.path
和 url_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 request和 for the request object itself .
您可能需要使用 request.script_root + request.path
。
关于python - request.path 和 url_for 在 mod_wsgi 下的 Flask 中不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15093593/