python - AttributeError: 'NoneType' object has no attribute 'sqlite_db' -
i don't understand how works. got code flaskr example. used work , doesn't.
i getting following error: attributeerror: 'nonetype' object has no attribute 'sqlite_db'
offending line: top.sqlite_db = sqlite_db
from champnotif_v2 import app flask import _app_ctx_stack, g import sqlite3 def get_db(): """opens new database connection if there none yet current application context. """ top = _app_ctx_stack.top if not hasattr(top, 'sqlite_db'): sqlite_db = sqlite3.connect(app.config['database']) sqlite_db.row_factory = sqlite3.row top.sqlite_db = sqlite_db return top.sqlite_db
__init__.py
from flask import flask app = flask(__name__) app.config.from_pyfile('info.py') import champnotif_v2.views
info.py
database = "freechamp.db"
it appears top
none
, not whatever expecting be. therefore _app_ctx_stack.top
must none
top
being set to. need work out why _app_ctx_stack.top
none
, fix that, or if expected add check before using top
in way, example:
top = _app_ctx_stack.top ... if top not none: top.sqlite_db = sqlite_db