【发布时间】:2013-08-15 09:28:49
【问题描述】:
我正在尝试访问包 api 中的蓝图 authorisation.py 中的访问应用程序配置。我正在初始化__init__.py 中的蓝图,它在authorisation.py 中使用。
__init__.py
from flask import Blueprint
api_blueprint = Blueprint("xxx.api", __name__, None)
from api import authorisation
授权.py
from flask import request, jsonify, current_app
from ..oauth_adapter import OauthAdapter
from api import api_blueprint as api
client_id = current_app.config.get('CLIENT_ID')
client_secret = current_app.config.get('CLIENT_SECRET')
scope = current_app.config.get('SCOPE')
callback = current_app.config.get('CALLBACK')
auth = OauthAdapter(client_id, client_secret, scope, callback)
@api.route('/authorisation_url')
def authorisation_url():
url = auth.get_authorisation_url()
return str(url)
我收到 RuntimeError: working outside of application context
我明白为什么会这样,但是访问这些配置设置的正确方法是什么?
----更新---- 暂时,我已经这样做了。
@api.route('/authorisation_url')
def authorisation_url():
client_id, client_secret, scope, callback = config_helper.get_config()
auth = OauthAdapter(client_id, client_secret, scope, callback)
url = auth.get_authorisation_url()
return str(url)
【问题讨论】:
标签: flask