4

I am working on a small web project using Flask/Python. This is a simple client side application without database.

I want to set the REST service address as a global attribute, but haven't figured out how to do that.

I know that attributes can be seted in flask.config like this:

app = Flask(__name__)
app.config['attribute_name'] = the_service_address

but the Blueprint module cannot access the 'app' object.

Thanks a lot for your time.

4

1 に答える 1

8

リクエスト コンテキスト内 (つまり、ビュー/ハンドラー内) で構成にアクセスできます。current_app

from flask import current_app
current_app.config['attribute_name']
于 2012-08-27T14:02:58.080 に答える