简体   繁体   English

使用 python flask 应用程序部署到 heroku 时 Procfile / wsgi 出现问题 ~ 找不到属性

[英]Problem with Procfile / wsgi when deploying to heroku with python flask app ~ Failed to find attribute

boiler-plate-code: My Github Repo样板代码:我的 Github Repo

 

Procfile:简介:

web: gunicorn myapi:create_app --log-file -     

Heroku logs: 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 : __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.不确定这样做的更好方法,但是, imgur_link是您可以找到我为我的项目设置的目录的地方。

My problem is, that I cannot figure out how to deploy to heroku.我的问题是,我无法弄清楚如何部署到 heroku。 I am attempting to use gunicorn as a webservice, as this is needed when deploying to heroku.我正在尝试使用 gunicorn 作为网络服务,因为在部署到 heroku 时需要这样做。 Could really use some help to figure out how to do so / find the correct code for my Procfile... Thank you in advance!真的可以使用一些帮助来弄清楚如何做到这一点/为我的 Procfile 找到正确的代码......在此先感谢您!

解决方法: Procfile: gunicorn "myapi:create_app()" --log-file - 请注意,需要引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM