boiler-plate-code: My Github Repo
过程文件:
web: gunicorn myapi:create_app --log-file -
Heroku 日志:
2020-01-25T11:07:56.952951+00:00 heroku[web.1]: Starting process with command `gunicorn myapi:create_app --log-file -`
2020-01-25T11:07:59.205710+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-25T11:07:58.973586+00:00 app[web.1]: [2020-01-25 11:07:58 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-01-25T11:07:58.974163+00:00 app[web.1]: [2020-01-25 11:07:58 +0000] [4] [INFO] Listening at: http://0.0.0.0:27984 (4)
2020-01-25T11:07:58.974256+00:00 app[web.1]: [2020-01-25 11:07:58 +0000] [4] [INFO] Using worker: sync
2020-01-25T11:07:58.979663+00:00 app[web.1]: [2020-01-25 11:07:58 +0000] [9] [INFO] Booting worker with pid: 9
2020-01-25T11:07:58.983867+00:00 app[web.1]: Failed to find attribute 'create_app' in 'myapi'.
2020-01-25T11:07:58.984029+00:00 app[web.1]: [2020-01-25 11:07:58 +0000] [9] [INFO] Worker exiting (pid: 9)
2020-01-25T11:07:58.993260+00:00 app[web.1]: [2020-01-25 11:07:58 +0000] [10] [INFO] Booting worker with pid: 10
2020-01-25T11:07:58.997526+00:00 app[web.1]: Failed to find attribute 'create_app' in 'myapi'.
2020-01-25T11:07:58.997674+00:00 app[web.1]: [2020-01-25 11:07:58 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-01-25T11:07:59.123159+00:00 app[web.1]: [2020-01-25 11:07:59 +0000] [4] [INFO] Shutting down: Master
2020-01-25T11:07:59.123241+00:00 app[web.1]: [2020-01-25 11:07:59 +0000] [4] [INFO] Reason: App failed to load.
2020-01-25T11:07:59.187524+00:00 heroku[web.1]: Process exited with status 4
__init__.py
:
from flask import Flask
from os import environ
from .commands import create_users, create_database
from .extensions import db, guard
from .models import User
from .routes import api
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = environ.get('SECRET_KEY')
app.config['SQLALCHEMY_DATABASE_URI'] = environ.get('SQLALCHEMY_DATABASE_URI')
app.config['JWT_ACCESS_LIFESPAN'] = {'minutes': 30}
db.init_app(app)
guard.init_app(app, User)
app.cli.add_command(create_users)
app.cli.add_command(create_database)
app.register_blueprint(api)
return app
not really sure a better way of doing this, however, imgur_link is where you will find the directory setup I have for my project.
我的问题是,我不知道如何部署到heroku。我正在尝试使用gunicorn作为网络服务,因为部署到heroku时需要它。确实可以使用一些帮助来弄清楚如何执行此操作/找到我的 Procfile 的正确代码... 预先感谢您!
最佳答案
解决方法: Procfile:gunicorn“myapi:create_app()”--日志文件- 请注意,需要报价。
关于python - 使用 python Flask 应用程序部署到 heroku 时 Procfile/wsgi 出现问题 ~ 找不到属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59908738/