也许我做错了什么。我正在尝试将flask-security-too
auth_required
与烧瓶的MethodView
配合使用,如https://flask.palletsprojects.com/en/1.1.x/views/#decorating-views所述,当我尝试访问该页面时,出现了异常。 python 3.6.8
from flask_security import auth_required
class RunningRoutesAdmin(MethodView):
decorators = [auth_required]
def get(self):
return render_template('admin.jinja2',
pagename='Admin Home')
admin_view = RunningRoutesAdmin.as_view('admin')
app.add_url_rule('/admin/', view_func=admin_view, methods=['GET',])
例外
Traceback (most recent call last):
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\lking\Documents\Lou's Software\projects\runningroutes\runningroutes\venv\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
TypeError: wrapper() missing 1 required positional argument: 'fn'
答案 0 :(得分:1)
好-简单的解决方案-由于auth_required需要参数-您需要:
decorators = [auth_required()]
对不起-我建议传递“无”-这当然是不正确的。不传递任何内容或传递可接受的方法列表(例如“会话”,“令牌”)都可以。