2016-08-01 2 views
0

Flask-JWT를 내 응용 프로그램과 함께 사용하고 싶습니다. current_app으로 초기화하려고하면 오류가 발생합니다. 이 시점까지 나는 app = Flask(__name__) 대신 current_app을 성공적으로 사용하여 예상치 못한 결과를 보였습니다. 내가 빠진 것이 있습니까?Flask-JWT가 current_app을 인식하지 못하는 것 같습니다.

당신은 당신이 실제로 그것을 사용하기 전에 클래스 'CURRENT_APP'를 초기화 할 필요가
Traceback (most recent call last): 
    File "./wsgi.py", line 1, in <module> 
    from main import app as application 
    File "./main.py", line 5, in <module> 
    from auth import api_auth 
    File "./auth.py", line 59, in <module> 
    jwt = JWT(current_app, authenticate, identity) 
    File "/opt/mist_base/env/lib/python2.7/site-packages/flask_jwt/__init__.py", line 216, in __init__ 
    self.init_app(app) 
    File "/opt/mist_base/env/lib/python2.7/site-packages/flask_jwt/__init__.py", line 220, in init_app 
    app.config.setdefault(k, v) 
    File "/opt/mist_base/env/lib/python2.7/site-packages/werkzeug/local.py", line 343, in __getattr__ 
    return getattr(self._get_current_object(), name) 
    File "/opt/mist_base/env/lib/python2.7/site-packages/werkzeug/local.py", line 302, in _get_current_object 
    return self.__local() 
    File "/opt/mist_base/env/lib/python2.7/site-packages/flask/globals.py", line 51, in _find_app 
    raise RuntimeError(_app_ctx_err_msg) 
RuntimeError: Working outside of application context. 
+0

current_app는 무엇을 기대합니까? (요청 외의 다른 항목으로 설정되지 않았습니다.) 확장 프로그램을 초기화 할 때 실제 앱을 전달하지 않는 이유는 무엇입니까? – davidism

+0

이 내 main.py에있는 것입니다 : '플라스크 수입 플라스크, 청사진,는 render_template, 세션, url_for, 재 탈출, 요청, ... 응용 프로그램 = 플라스크 (__ name__) 의 app.config를 중단에서 .from_pyfile ("./config.py") ... app.register_blueprint (api_auth) ' 최대이 시점까지 나는 플라스크가 자동으로 app_current_app를 통해 앱 컨텍스트를 전파한다는 인상을 받았다. config.py를 업데이트하면 청사진 노드에서 상수 값을 볼 수 있습니다. – goterpsgo

답변

0

from flask import current_app 
from flask_jwt import JWT 

def authenticate(username, password): 
    ... 
    return user 

def identity(payload): 
    ... 
    return userid_table.get(user_id, None) 

jwt = JWT(current_app, authenticate, identity) 
.

current_app = Flask(__name__) 
관련 문제