我有一个适用于开发的应用程序,但是当我尝试使用Gunicorn运行它时,它会出现“sqlalchemy扩展未注册”的错误.从我所看到的,似乎我需要在某处调用app.app_context(),但我不知道在哪里.我该如何解决这个错误?
# run in development,works
python server.py
# try to run with gunicorn,fails
gunicorn --bind localhost:8000 server:app
AssertionError: The sqlalchemy extension was not registered to the current application. Please make sure to call init_app() first.
server.py:
from flask.ext.security import Security
from database import db
from application import app
from models import Studio,user_datastore
security = Security(app,user_datastore)
if __name__ == '__main__':
# with app.app_context(): ??
db.init_app(app)
app.run()
application.py:
from flask import Flask
app = Flask(__name__)
app.config.from_object('config.ProductionConfig')
database.py:
from flask.ext.sqlalchemy import sqlAlchemy
db = sqlAlchemy()
最佳答案
原文链接:https://www.f2er.com/nginx/434599.html