gpt4 book ai didi

python - key 错误 : 'security' in Flask_security?

转载 作者:太空宇宙 更新时间:2023-11-03 13:42:04 27 4
gpt4 key购买 nike

我正在使用 Flask 构建一个网站,我现在正尝试在其中使用 Flask_Security用于基于 token 的身份验证。我现在想从用户那里得到一个 auth_token,为此我使用 get_auth_token() method .不幸的是,我得到了这条消息下方的堆栈跟踪。

有人知道怎么回事吗?欢迎所有提示!

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/kramer65/myapp-kram/app/views/apiviews.py", line 33, in api_login
return jsonify({'token': user.get_auth_token()})
File "/usr/local/lib/python2.7/dist-packages/flask_security/core.py", line 313, in get_auth_token
return _security.remember_token_serializer.dumps(data)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 338, in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 297, in _get_current_object
return self.__local()
File "/usr/local/lib/python2.7/dist-packages/flask_security/core.py", line 30, in <lambda>
_security = LocalProxy(lambda: current_app.extensions['security'])
KeyError: 'security'

最佳答案

您需要为您的应用初始化扩展。

security = Security()
security.init_app(app, user_datastore)

See the quickstart in the docs.

关于python - key 错误 : 'security' in Flask_security?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28724513/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com