金字塔 pserve 在与/不同的根路径中 [英] pyramid pserve in different root path than /

查看:54
本文介绍了金字塔 pserve 在与/不同的根路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,当 pserve 启动时,它会在 http://0.0.0.0:6543 中运行金字塔应用程序,但是如何将其更改为 http://0.0.0.0:6543/myapp

When pserve starts by default it runs the pyramid application in http://0.0.0.0:6543 however how can I changed it to http://0.0.0.0:6543/myapp

在设置中我可以更改端口,但我还没有在其他地方找到更改根路径的位置

In the settings I can change the port but I haven't found elsewhere where to change the root path

推荐答案

在任何 WSGI 应用程序中,environ['SCRIPT_NAME'] 在这里非常重要.它定义了应用程序中所有 url 的根路径.完整路径是 environ['SCRIPT_NAME'] + environ['PATH_INFO'].假设您在应用程序中正确完成了操作(例如 request.route_url(..) 将使用此信息生成网址),那么您可以简单地在其他地方重新安装您的应用程序(默认的 SCRIPT_NAME'') 通过指示它应该是别的东西.

In any WSGI application the environ['SCRIPT_NAME'] is very important here. It defines the root path for all urls in the app. The full path is environ['SCRIPT_NAME'] + environ['PATH_INFO']. Assuming you have done things properly in your app (for example request.route_url(..) will generate urls using this information) then you can simply remount your application elsewhere (the default SCRIPT_NAME is '') by instructing it that it should be something else.

根据您部署应用程序的方式,您可以做一些事情(如果它在代理后面,那么事情会稍微复杂一些).假设您只是使用一个由女服务员托管的简单金字塔应用程序.您可以使用 rutter[1] 包移动您的应用,该包将匹配 /myapp/* 路径,并使用适当的 SCRIPT_NAME<将所有请求发送到您的应用/code> (myapp) 和 PATH_INFO.

There are a couple things you can do based on how you're deploying your application (if it's behind a proxy then things are slightly more complex). Let's assume you're just using a simple pyramid app hosted with waitress. You can move your app using the rutter[1] package which will match the /myapp/* path and send all requests to your app with the appropriate SCRIPT_NAME (myapp) and PATH_INFO.

声明性配置对于金字塔应用程序来说是最简单的.只需安装 rutter 然后更新您的 INI 文件以在 /myapp 前缀挂载您的应用程序:

The declarative config is the simplest for a pyramid app. Just install rutter and then update your INI file to mount your application at /myapp prefix:

[app:foo]
use = egg:myapp#main

[composite:main]
use = egg:rutter#urlmap
/myapp = foo

注意我将 app:main 重命名为 app:foo 因为你只能有一个名为 main 的 wsgi 组件,我们希望它成为复合体.

Note I renamed the app:main to app:foo because you can only have one wsgi component named main and we want it to be the composite.

[1] http://rutter.readthedocs.io/en/latest/#declarative-configuration-using-paste-deploy-ini-files

这篇关于金字塔 pserve 在与/不同的根路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆