主程序__init__.py
from flask import Flask
import config
from .blueprints.edit import edit_bp
from .extensions import db
def create_app():
app = Flask(__name__)
app.config.from_object(config)
@app.route('/')
def index():
return 'Index Page'
db.init_app(app)
db.reflect(app=app)
all_table = {table_obj.name: table_obj for table_obj in db.get_tables_for_bind()}
for key in all_table.keys():
print(key)
app.register_blueprint(edit_bp, url_prefix='/edit')
return app
edit.py
from flask import Blueprint
edit_bp = Blueprint('edit', __name__)
@edit_bp.route('/')
def edit():
test = db.session.query(all_table['test_tbl']).filter_by(tag='Flask').all()
return 'edit'
在edit.py中需要用到主程序中的db和all_table,那么应该如何导入?
谢谢!!