Skip to main content
 首页 » 编程设计

python之环境变量或 pserve 参数中的 Pyramid 服务器端口

2025年05月04日11虾米哥

我想通过环境变量或命令行参数指定 Pyramid 的服务器端口(使用默认 pserve)。以前有人这样做过吗?

请您参考如下方法:

pserve --help 命令告诉我们:

Usage: pserve-script.py config_uri [start|stop|restart|status] [var=value]

This command serves a web application that uses a PasteDeploy configuration file for the server and application. If start/stop/restart is given, then --daemon is implied, and it will start (normal operation), stop (--stop- daemon), or do both. You can also include variable assignments like 'http_port=8080' and then use %(http_port)s in your config files.

所以,例如:

[server:main] 
use = egg:waitress#main 
host = 127.0.0.1 
port = %(http_port)s 

并运行 pserve mydevapp.ini http_port=1234