I'm building a website using the Flask Framework, in which I've got a folder in which I have some python files and an __init__.py
script (I guess you would call this folder a module?). In the init.py file I've got a line saying:
db = Database(app)
I now want to use db
in a different script which is in this folder. Normally I would do this using from __init__ import db
, but that just doesn't seem right to do, let alone pythonic. Furthermore, since it is in the __init__.py
file, I suppose it should somehow be initialised for the whole folder/module.
Does anybody know how I can use db
from the __init__.py
file? All tips are welcome!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…