我修改了代码后发现它是错误的,现在我无法使用gunicorn来运行它。如果您从此处开始有关于结构化或分解的建议,也欢迎您。 我正试图让它从5天开始运行,苦苦挣扎。
目录结构
app--
--db.sqlite
--__init__.py
--models.py
--MyFunctions.py
--routes.py
--schemas.py
--sockets.py
app.py
内部app.py
from app import *
from app.MyFunctions import *
from app.models import *
from app.schemas import *
from app.routes import *
from app.sockets import *
port=os.environ.get("PORT")
if port is None or port == "":
port = 3000
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=port) # when running on heroku
在 init .py
内部import jwt
from flask import (
Flask,
request,
jsonify,
make_response,
)
from flask_socketio import (
SocketIO,
send,
emit,
join_room,
leave_room,
)
from sqlalchemy import (
Column,
Integer,
String,
Boolean,
ForeignKey,
DateTime,
Sequence,
Float,
)
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from os import environ
def debug(msg):
print('\n\n\n'+str(msg)+'\n\n\n'+'\n\nType:\t'+str(type(msg))+'\n\n')
from .models import *
socketio = SocketIO(app, cors_allowed_origins='*')
models.py内部(仅导入与模型相关的东西,我的大部分导入仅位于此处)
from flask import (
Flask,
request,
jsonify,
make_response,
redirect,
)
from flask_socketio import (
SocketIO,
send,
emit,
join_room,
leave_room,
)
from sqlalchemy import (
Column,
Integer,
String,
Boolean,
ForeignKey,
DateTime,
Sequence,
Float,
)
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from flask_bcrypt import Bcrypt
from os import environ
from flask_cors import CORS, cross_origin
app = Flask(__name__)
root = os.path.dirname(os.path.abspath(__file__))
CORS(app, support_credentials=True)
basedir = os.path.abspath(os.path.dirname(__file__))
PG = os.environ.get("DATABASE_URL")
if PG is None or PG=="":
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
os.path.join(basedir, 'db.sqlite')
else:
app.config['SQLALCHEMY_DATABASE_URI'] = PG
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = environ.get('STRIPE_API_KEY')
db = SQLAlchemy(app)
ma = Marshmallow(app)
bcrypt = Bcrypt(app)
socketio = SocketIO(app, cors_allowed_origins='*')
编辑: 目前,我仅使用python在heroku上运行该应用程序,因此我的Procfile看起来像
web: python app.py
是的,我尝试了许多其他格式,例如
web: gunicorn app:app
web: gunicorn models:app
web: gunicorn app/models:app
还尝试通过制作不同的运行文件和许多其他方法 恐怕我需要更改其结构才能使其正常工作。
答案 0 :(得分:1)
我重命名了app.py文件,然后它起作用了
内部Procfile
web: gunicorn gettingstarted.wsgi
web: gunicorn runner:app