flask-admin中使用flask-login实现登录,但是登录时任意密码都可以登陆。

并且使用不存在的用户名登录时总是报错:
if not force and not user.is_active():
AttributeError: 'NoneType' object has no attribute 'is_active'

def is_active(self):
    return True

代码就是参考flask-admin的auth例子写的。

阅读 10.9k
1 个回答


admin_app = Admin(name='chahua3287',index_view=MyAdminIndexView())
#主页视图
class MyAdminIndexView(admin.AdminIndexView):
    #增加这个必须要登录后才能访问,不然显示403错误
    #但是还是不许再每一个函数前加上这么判定的  ,不然还是可以直接通过地址访问
    def is_accessible(self):
        return login.current_user.is_authenticated

    #跳转
    def inaccessible_callback(self, name, **kwargs):
        return redirect(url_for('auth.login', next=request.url))

    #后台首页   
    @admin.expose('/')
    def index(self):
        return self.render('admin/index.html')
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题