Flask, как получить доступ к контексту приложения из другого модуля, а не из функции?
Иметь файловую структуру
testapp.py
| - testfolder
|-testfile.py
testapp.py
from flask import Flask
from testfolder.testfile import testmodule
app = Flask(__name__)
app.register_blueprint(testmodule, url_prefix='/test')
if __name__ == "__main__":
app.run(debug=True)
testfile.py
from flask import Blueprint, current_app as app
testmodule = Blueprint('testmodule', __name__)
app.config['test '] = '123'
@testmodule.route('/')
def index():
print(app.config['test'])
return "request is ok"
Ошибка при попытке запустить приложение
app.config['test '] = '123' ^^^^^^^^^^ RuntimeError: Working outside of application context.
This typically means that you attempted to use functionality that needed the current application. To solve this, set up an application context with app.app_context(). See the documentation for more information. Blockquote
Я так понимаю, что я неправильно задаю параметр контекста, вопрос как правильно задать параметр контекста вне функции при инициализации модуля?