nginx C 在使用Gunicorn运行应用程序时未注册SQLAlchemy扩展
发布时间:2023-12-18 23:27:21 所属栏目: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 /index.html到/重写
- bash – 找不到NGINX brew install命令
- Nginx URL屏蔽到不同的域
- python-Ngnix Gunicorn Flask:如何找出真正的基本URL
- Nginx C PHP脚本上的基本http身份验证
- 从源安装nginx-1.7.8时,Chef :: Exceptions :: ChecksumMis
- php – Nginx – Rails中的WordPress博客使用mime类型的文本
- nginx – 为子目录指定不同的索引文件名
- ruby-on-rails – nginx没有在Rails静态资产上设置expires头
- nginx – 使用symfony3提供远程静态文件
推荐文章
站长推荐
- NGINX $request_uri vs $uri
- node.js – 带有NGINX proxy_pass的Webpack Dev
- 在Nginx中解释limit_conn_zone $server_name
- 如何从nginx响应中删除某些cookie
- Nginx:将非www重定向到www https
- nginx – server_tokens关闭但仍然发布它们
- ruby-on-rails – 是否有必要将Unicorn放在Nginx
- ruby-on-rails – nginx没有在Rails静态资产上设
- Laravel Homestead vhost配置
- 无法使用Nginx(反向代理SSL协商)和Tomcat上传大文
