nginx C 在使用Gunicorn运行应用程序时未注册SQLAlchemy扩展
发布时间:2023-12-18 23:27: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). (编辑:阜阳站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 重要:Nginx配置中的fastcgi参数性能优化和含义
- 如何在NGINX中设置自定义的503错误页面?
- nginx – 无法用石墨配置grafana
- nginx-超时后不友好的工作人员终止
- nginx – server_tokens关闭但仍然发布它们
- 带有Docker的WordPress和Nginx:未加载静态文件
- node.js – 带有NGINX proxy_pass的Webpack Dev Server
- nginx accept() failed (24: Too many open files)
- 如何避免在nginx中重复add_header指令?
- NGINX Proxy_Pass删除url substring
推荐文章
站长推荐