Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting global attributes in Flask framework

Tags:

python

flask

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.

like image 376
Steven You Avatar asked Feb 20 '23 09:02

Steven You


1 Answers

Within a request context (i.e. in a view/handler) you can access the config on the current_app

from flask import current_app
current_app.config['attribute_name']
like image 117
Rob Cowie Avatar answered Feb 22 '23 03:02

Rob Cowie