我已经检查了文档,并且如何实现is_accessible方法非常模糊.
以下是烧瓶管理员的文档显示的内容
class MicroBlogModelView(sqla.ModelView):
def is_accessible(self):
return login.current_user.is_authenticated()
def inaccessible_callback(self, name, **kwargs):
# redirect to login page if user doesn't have access
return redirect(url_for('login', next=request.url))
Run Code Online (Sandbox Code Playgroud)
我不知道的是你怎么称呼它是自动调用还是你必须像这样自己调用它:
@expose("/", methods=["GET", "POST"])
def home(self):
if self.is_accesible():
return super().index()
else:
return self.login()
def is_accesible(self):
return current_user.is_authenticated and "admin" in current_user.role
Run Code Online (Sandbox Code Playgroud)
因为放一个是非常重复的
if self.is_accesible():
return super().index()
Run Code Online (Sandbox Code Playgroud)
检查我们是否有很多管理员观点.那么我们究竟是如何实现它的呢?文档展示了如何将它放在您的模型中,而不是如何在您的视图上实现它