如何将我的 Flask_socketio 应用程序正确推送到 Heroku?

时间:2021-04-03 22:10:19

标签: python flask heroku

我一直试图将我的 Flask_socketio 应用程序推送到 Heroku,但 Heroku 无法通过 Procfile 找到我的应用程序,可能是因为我的包结构。如何重构我的目录?或者,我应该更改我的 Procfile.txt 吗?提前致谢。

我的目录结构:


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(762, 590)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.checkBox = QtWidgets.QCheckBox('box', self.centralwidget)
        self.checkBox.setGeometry(QtCore.QRect(150, 75, 181, 20))
        self.checkBox.setObjectName("checkBox")


        self.comboBox = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox.setGeometry(QtCore.QRect(150,160,100,20))
        self.comboBox.addItem("UNHIDE")
        self.comboBox.addItem("HIDE")
        self.comboBox.setObjectName("comboBox")


        MainWindow.setCentralWidget(self.centralwidget)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.comboBox.currentTextChanged.connect(self.hidefunction) # code for connect to function below

    def hidefunction(self):
        text = str(self.comboBox.currentText()) 
        # this is the state of the current text in combobox. Below simple IF block.
        if text == "UNHIDE":
            self.checkBox.setHidden(False) 
        # its HIDE - your checkBox when comboBox changed his state 
        else:
            self.checkBox.setHidden(True) 
        # its HIDE your checkBox when comboBox changed his state 
    
           

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "11"))

        MainWindow.show()

if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

App.py:

|App
| |-templates
| |-main
| |-__init__.py
|app.py
|requirements.txt
|Procfile

app/init.py:

from app import create_app, socketio

app = create_app(debug=True)

if __name__ == "__main__":
    socketio.run(app)

Procfile:

from flask import Flask
from flask_socketio import SocketIO

socketio = SocketIO()

def create_app(debug=False):
    "Create an application."

    app = Flask(__name__)
    app.debug = debug
    app.config['SECRET_KEY'] = 'MRHBLR'

    from .main import main 
    app.register_blueprint(main)

    socketio.init_app(app)
    return app

Heroku 应用的日志:

web: gunicorn --worker-class eventlet -w 1 app:app

1 个答案:

答案 0 :(得分:0)

您的顶级似乎有两个名为 Python 3.6.5 的东西,对吗?您有 SimLoRD 文件和 app 包。这是行不通的,尝试重命名其中之一。例如,将 app.py 更改为 app,然后在 Gunicorn 命令行中传递 app.py

相关问题