pyramid pserve in different root path than /

夙愿已清 提交于 2019-12-13 07:18:32

问题


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


回答1:


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.

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.

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

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



来源:https://stackoverflow.com/questions/43502411/pyramid-pserve-in-different-root-path-than

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!