0
Ich möchte Flask-JWT mit meiner App verwenden. Wenn ich versuche, es mit current_app
zu initialisieren, erhalte ich einen Fehler. Bis zu diesem Punkt habe ich current_app
erfolgreich anstelle von app = Flask(__name__)
verwendet, so dass dies ein bisschen unerwartet war. Gibt es etwas, das mir fehlt?Flask-JWT scheint nicht zu erkennen 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.
Was erwarten Sie von current_app? (Es ist nicht auf etwas außerhalb einer Anfrage festgelegt.) Warum übergeben Sie nicht Ihre eigentliche App beim Initialisieren der Erweiterung? Diese – davidism
ist das, was ich in meinem main.py haben: 'von Kolben Import Flask, Blaupause, render_template, Sitzung, Umleiten, url_for, Flucht, Anfrage, abbrechen ... app = Flask (__ name__) app.config .fr_pyfile ("./config.py") ... app.register_blueprint (api_auth) ' Bis zu diesem Punkt hatte ich den Eindruck, Flask würde App-Kontext über current_app automatisch propagieren. Ich kann meine konstanten Werte in meinen Blueprint-Knoten sehen, wenn ich config.py aktualisiere. – goterpsgo