nginx C 在使用Gunicorn运行应用程序时未注册SQLAlchemy扩展
发布时间:2023-12-19 20:25:22 所属栏目:Nginx 来源:DaWei
导读: 我有一个适用于开发的应用程序,但是当我尝试使用Gunicorn运行它时,它会出现“sqlalchemy扩展未注册”的错误.从我所看到的,似乎我需要在某处调用app.app_context(),但我不知道在哪里.我该如何
我有一个适用于开发的应用程序,但是当我尝试使用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() 最佳答案 只有当您使用python sever.py启动应用程序时,if __name__ ==’__ main__’:阻止命中,您将在应用程序中注册数据库.您需要在该块之外移动该行db.init_app(app). (编辑:商洛站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐