I am trying to access configuration value from my Flask application object outside view function. As I understand from official docs, we can access Flask app instance thats currently running with the help of proxy object called current_app, we can import it with command: from flask import current_app. I need to access config value outside view function. I am using third party API to send sms from my application. I wrote code for this in another separate module and need to access config values in order to initialize custom objects of this third party library. Here is the code snippets that I wrote inside my module:
from third_party_api import Configuration
from flask import current_app
configuration = Configuration()
configuration.username = current_app.config['third_party_api_username']
configuration.password = current_app.config['third_party_api_password']
Here is the snapshot of RuntimeError I get:
As I understand, we can access current_app config object inside view function without any problem. I dont want to access config value directly from configuration file or class. I read the docs, but it didnt help.