nginx C 在使用Gunicorn运行应用程序时未注册SQLAlchemy扩展
发布时间:2023-12-18 23:57:43 所属栏目: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). (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – rails – nginx puma – 静态资产不是由提
- win 下 nginx 与 php的配置
- python – 在Nginx反向代理POST请求后面的CherryPy被破坏/截
- nginx fastcgi与django的问题(url中的双斜线?)
- django – nginx不提供管理静态文件?
- python – 无法启动uwsgi进程
- nginx – 当服务器IP发生变化时,excing TCP(例如http/mysql
- 从Nginx中的Set-Cookie标头登录值
- nginx accept() failed (24: Too many open files)
- php-页面无法正确重定向Nginx
推荐文章
站长推荐