【发布时间】:2020-03-04 22:09:07
【问题描述】:
我希望能够从 Pluggable View 类访问 app.config
我有什么: 烧瓶应用、可插拔视图、蓝图
from flask import current_app
# using pluggable views
class Router(MethodView):
# applying flask_login.login_required to all methods
# in the current class
decorators = [flask_login.login_required]
def get(self, *args, **kwargs):
pass
def post(self, *args, **kwargs):
pass
我想要什么: (这不起作用,因为没有应用程序/请求上下文,并且未设置 current_app)
from flask import current_app
class Router(MethodView):
# this does not work
if current_app.config['LOGIN_REQUIRED']:
decorators = [flask_login.login_required]
def get(self, *args, **kwargs):
pass
def post(self, *args, **kwargs):
pass
【问题讨论】: