在gunicorn 中使用额外的命令行参数
假设我按照 http://gunicorn.org/deploy.html#runit 在 Gunicorn 下启动 Flask 应用程序,有没有办法让我包含/解析/访问额外的命令行参数?
例如,我可以以某种方式在 Flask 应用程序中包含并解析 foo 选项吗?
gunicorn mypackage:app --foo=bar
谢谢,
Assuming I'm starting a Flask app under gunicorn as per http://gunicorn.org/deploy.html#runit, is there a way for me to include/parse/access additional command line arguments?
E.g., can I include and parse the foo
option in my Flask application somehow?
gunicorn mypackage:app --foo=bar
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法直接传递命令行参数,但您可以轻松选择应用程序配置。
将调用函数“build_app”并按预期传递 foo="bar" kwarg。然后,该函数应返回将使用的 WSGI 可调用函数。
You can't pass command line arguments directly but you can choose application configurations easily enough.
Will call the function "build_app" passing the foo="bar" kwarg as expected. This function should then return the WSGI callable that'll be used.
我通常把它放在
main()
之后的__init.py__
中,然后我可以在有或没有gunicorn的情况下运行(假设你的main()
支持其他也有功能)。这样您就可以简单地使用eg 运行,
并且您的
main()
可以使用需要sys.argv
中的参数的标准代码。I usually put it in
__init.py__
aftermain()
and then I can run with or without gunicorn (assuming yourmain()
supports other functions too).That way you can run simply with e.g.
and your
main()
can use standard code that expects the arguments insys.argv
.