Answers
用全局g应该可以吧,
http://flask.pocoo.org/docs/0.10/api/#flask.g
还有current_app
我试了下current_app,可以啊
目录
test
--app
--__init__.py
--home.py
--instance
--config.py
--run.py
# app/__init__.py
from flask import Flask
from .home import home
def create_app():
app = Flask(__name__, instance_relative_config=True)
app.config.from_pyfile('config.py')
app.register_blueprint(home)
return app
# app/home.py
from flask import Blueprint, current_app
home = Blueprint('home', __name__)
@home.route('/')
def helle():
return 'hello home '+current_app.config['TEST']
# instance/config.py
# capitalize
DEBUG=True
TEST='wo'
# run.py
from app import create_app
app = create_app()
app.run(debug=app.config['DEBUG'])
史前大龙虾
answered 10 years, 1 month ago