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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -