def get_db(self,dbfile):
if hasattr(g, 'sqlite_db'): self.close_db(g.sqlite_db)
try:
g.sqlite_db = self.connect_db('{}/{}'.format(app.root_path, dbfile))
except sqlite3.OperationalError as e:
raise e
return g.sqlite_db
Hi mã này nằm bên trong lớp DB, Các lỗi tôi nhận được làngoài làm việc của bối cảnh ứng dụng - Flask
RuntimeError: working outside of application context
lỗi xảy ra trên đường dây này
g.sqlite_db = self.connect_db('{}/{}'.format(app.root_path, dbfile))
Tôi nghĩ rằng vấn đề là với g, nó được nhập như thế from flask import g
Lỗi này có thể được sửa? Cảm ơn.