0
我想在我的應用程序中使用Flask-JWT。當我嘗試用current_app
初始化它時,出現錯誤。到目前爲止,我一直使用current_app
代替app = Flask(__name__)
,所以這有點意外。有什麼我失蹤?Flask-JWT似乎無法識別current_app
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)
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.
你期望current_app是什麼? (它不會被設置爲請求外的任何內容。)爲什麼在初始化擴展時不傳遞實際的應用程序? – davidism
這是我在我的main.py: '從瓶進口瓶,藍圖,render_template,會話,重定向,url_for,逃生,請求中止 ... 應用=瓶(__ name__) 的app.config .from_pyfile(「./ config.py」) ... app.register_blueprint(api_auth)' 到目前爲止,我在印象之下Flask會自動通過current_app傳播應用上下文。當我更新config.py時,我能夠在藍圖節點中看到我的常量值。 – goterpsgo