1

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: enter image description here

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.

AmacOS
  • 185
  • 11

1 Answers1

1

Solved by moving this piece of code to inside the function which is called inside another view function:

configuration = Configuration()
configuration.username = current_app.config['third_party_api_username']
configuration.password = current_app.config['third_party_api_password']
AmacOS
  • 185
  • 11