我试图将Flask应用程序部署到Heroku,但是我仍然遇到错误:“ ModuleNotFoundError:当我尝试在Heroku上打开站点时,没有名为“ app”的模块。
Procfile:
web: gunicorn run:app
run.py
from app import app
# from dir called app, import the object called app
if __name__ == '__main__':
app.run(debug=True)
Heroku日志:
2020-08-06T18:27:42.941260+00:00 app[web.1]: File "/app/run.py", line 1, in <module>
2020-08-06T18:27:42.941260+00:00 app[web.1]: from app import app
2020-08-06T18:27:42.941266+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
2020-08-06T18:27:42.941444+00:00 app[web.1]: [2020-08-06 18:27:42 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-08-06T18:27:43.049679+00:00 app[web.1]: [2020-08-06 18:27:43 +0000] [4] [INFO] Shutting down: Master
2020-08-06T18:27:43.049793+00:00 app[web.1]: [2020-08-06 18:27:43 +0000] [4] [INFO] Reason: Worker failed to boot.
2020-08-06T18:27:43.120147+00:00 heroku[web.1]: Process exited with status 3
项目树结构:
app.\
│ config.py
│ forms.py
│ migration.py
│ models.py
│ Procfile
│ requirements.txt
│ routes.py
│ run.py
│ site.db
│ __init__.py
│
├───main
├───migrations
├───posts
├───static
├───templates
├───users
答案 0 :(得分:0)
一切看起来都很好,您能否仅从应用程序导入应用程序更改并在同一文件中定义应用程序而不是导入,也许它开始起作用,因为我在这里看不到失败的地方,您可以在下面查找文章
https://stackabuse.com/deploying-a-flask-application-to-heroku/