uwsgi使用什么__name__字符串?

问题描述 投票:4回答:2

在uwsgi下运行时,这个例子中__name__的价值是多少?

if __name__ == '__main__':
    from livereload import Server
    server = Server(app.wsgi_app)
    server.serve()

我只想确保在Nginx下使用uwsgi将其推送到生产服务器时不会运行。

python nginx uwsgi
2个回答
4
投票

__name__将等于模块名称加上uwsgi导入应用程序的文件名。例如:my_project.server。所以块内的代码不会运行。

http://flask.pocoo.org/docs/1.0/deploying/uwsgi/


1
投票

答案是:

uwsgi_file__<filepath>

文件路径具有/s的下划线以及可能的其他替换。因此,当正在运行的脚本的路径是

  /opt/www/example.com/www/blog.py

__name__将是

  uwsgi_file__opt_www_example_com_www_blog

我确实不得不讨厌刺激,但我想我已经逃脱了。

© www.soinside.com 2019 - 2024. All rights reserved.