nginx - SQLAlchemy extension isn't registered when running app with Gunicorn -
i have application works in development, when try run gunicorn gives error "sqlalchemy extension not registered". i've read seems need call app.app_context()
somewhere, i'm not sure where. how fix error?
# run in development, works python server.py # try run gunicorn, fails gunicorn --bind localhost:8000 server:app assertionerror: sqlalchemy extension not registered current application. please make sure call init_app() first.
server.py
:
from flask.ext.security import security database import db application import app models import studio, user_datastore security = security(app, user_datastore) if __name__ == '__main__': # 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()
only when start app python sever.py
if __name__ == '__main__':
block hit, you're registering database app.
you'll need move line, db.init_app(app)
, outside block.
Comments
Post a Comment