首页 > 解决方案 > 使用 Gunicorn 在与 / 不同的路径中加载 Pyramid 应用程序

问题描述

我有一个使用 Gunicorn 加载的 Pyramid 应用程序。我的ini文件有以下内容:

[app:main]
use = egg:my_example
...
[server:main]
use = egg:gunicorn
host = localhost
port = 5900
workers = 1
worker_class = gevent

我用 Gunicorn 启动:

gunicorn --paste ./development.ini

所以我的应用程序可以在http://127.0.0.1:5900

我需要做什么才能使我的应用程序在其他路径而不是 / 中可用,例如http://127.0.0.1:5900/my_example

我看到了以下帖子: pyramid pserve in different root path than /Pyramid: how to set SCRIPT_NAME in request.environ但我仍然无法做到

标签: gunicornpyramid

解决方案


如果您希望所有传入的 url 从它们中删除前缀(例如,http://127.0.0.1:5900/my_example/foo/bar导航到/foo/bar应用程序中的路由),Rutter 是正确的答案。这似乎是您所描述的,并且https://stackoverflow.com/a/43506460/704327中的 ini 片段应该足够了。Rutter 还将正确地准备环境,以便您的应用程序/my_example在使用request.route_pathand时生成带有前缀的正确 url request.route_url


推荐阅读