2017-07-28 46 views
0

我命名的,而不是通常的app.py我的初始化文件__main__.py,因爲我想與如何在__main__.py中使用gunicorn?

$ python flask_api/ 

但現在運行它,當我試圖用Gunicorn使用它,它看起來這名限制:

$ gunicorn flask_api:app 
[2017-07-28 22:40:33 +0300] [15488] [INFO] Starting gunicorn 19.7.1 
[2017-07-28 22:40:33 +0300] [15488] [INFO] Listening at: http://127.0.0.1:8000 (15488) 
[2017-07-28 22:40:33 +0300] [15488] [INFO] Using worker: sync 
[2017-07-28 22:40:33 +0300] [15491] [INFO] Booting worker with pid: 15491 
Failed to find application: 'flask_api' 
[2017-07-28 22:40:33 +0300] [15491] [INFO] Worker exiting (pid: 15491) 
[2017-07-28 22:40:33 +0300] [15488] [INFO] Shutting down: Master 
[2017-07-28 22:40:33 +0300] [15488] [INFO] Reason: App failed to load. 

我也試着用另一種方式啓動它:

$ cd flask_api/ 
$ gunicorn __main__:app 
[2017-07-28 22:42:06 +0300] [15766] [INFO] Starting gunicorn 19.7.1 
[2017-07-28 22:42:06 +0300] [15766] [INFO] Listening at: http://127.0.0.1:8000 (15766) 
[2017-07-28 22:42:06 +0300] [15766] [INFO] Using worker: sync 
[2017-07-28 22:42:06 +0300] [15769] [INFO] Booting worker with pid: 15769 
Failed to find application: '__main__' 
[2017-07-28 22:42:06 +0300] [15769] [INFO] Worker exiting (pid: 15769) 
[2017-07-28 22:42:06 +0300] [15766] [INFO] Shutting down: Master 
[2017-07-28 22:42:06 +0300] [15766] [INFO] Reason: App failed to load. 

有什麼問題和浩我可以修復它嗎?

順便說一句,這裏是我flask_api/結構:

flask_api/ 
├── blueprints 
│   ├── add_methods.py 
│   └── get_methods.py 
├── config.py 
├── __main__.py 
└── README.md 

回答

0

您不能更改到不同的目錄,並期望相對進口工作相同。留在flask_api以上的目錄中,並使用gunicorn flask_api.__main__:app

此外,您依賴於相對導入,因此從任何地方運行,但在flask_api目錄中都無法按預期運行。將您的布​​局更改爲以下內容,並從project目錄運行。

project/ 
    flask_api/ 
    __init__.py 
    __main__.py 
    config.py 
    blueprint/ 
     __init__.py 
     add_methods.py 
     get_methods.py 
    README.md 
+0

感謝您的回答,但它仍然無效。導入有誤: 'from config import BaseConfig ImportError:No module named'config'' –

+0

謝謝你花費我的時間:)我已經添加了這兩個文件'__init __。py'(它們是空白的)和它仍然有相同的錯誤:( –

相關問題