【问题标题】:Flask with development server and uwsgi, config.from_object()带有开发服务器和 uwsgi 的烧瓶,config.from_object()
【发布时间】:2023-03-19 20:20:01
【问题描述】:

我的问题是我的 Flask 应用程序正在使用开发服务器或使用 uwsgi。这是我的布局。

project/
    project/
        static/
        templates/
        helper.py
        settings.py
        server.py
    uwsgi.ini

server.py 中的问题行

app.config.from_object('project.settings') # works with uwsgi

app.config.from_object('settings') # works with dev

我想从根目录启动网络服务器,使用“python project/server.py”或在生产环境中:uwsgi --ini uwsgi.ini

我的 uwsgi.ini 文件

[uwsgi]
module = project.server
....

“project.settings”的开发服务器错误

ImportError: No module named project.settings

带有“设置”的uwsgi

ImportError: No module named settings

有没有办法在不修改 PYTHONPATH 或使用 try/except 的情况下解决这个问题?

【问题讨论】:

    标签: python flask


    【解决方案1】:

    使用 chdir uWSGI 选项,您可以将其设置为与开发服务器从命令行运行 flask 时使用的目录相同的目录。

    在你的情况下,像

    chdir = XXX/项目/项目

    会成功的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 2018-02-02
      • 1970-01-01
      相关资源
      最近更新 更多