Flask-Admin 删除 "Home" 按钮

Flask-Admin remove "Home" button

如何删除 Python 的 Flask-Admin 库中的 "Home" 按钮?

from flask_admin import Admin

flask_admin = Admin(app, 
    name='Customer Admin', 
    template_mode='bootstrap3', 
    # endpoint refers to the blueprint [e.g. url_for('admin_cust.index')] where index() is the function/view
    index_view=SecuredAdminIndexView(url='/admin_cust', endpoint='admin_cust')
)

# Add model (database table) views to the page
flask_admin_cust.add_view(UserView(User, db.session, category='Users', name='View/Edit User', endpoint='users'))
flask_admin.add_view(CustSubGroupView(CustSubGroup, db.session, name='Groups', endpoint='groups'))
flask_admin.add_view(GwView(Gw, db.session, endpoint='units', name='Units'))

我找到了一种方法,至少可以更改默认名称 "Home"。

在下面的代码中,我的新名字是 'NOT HOME'。这是一个开始...

flask_admin = Admin(app, 
    name='Customer Admin', 
    template_mode='bootstrap3', 
    # endpoint refers to the blueprint [e.g. url_for('admin_cust.index')] where index() is the function/view
    index_view=SecuredAdminIndexView(name='NOT HOME', url='/admin_cust', endpoint='admin_cust')
)

Flask-Admin BaseView 有一个方法 is_visible(self)source code 有一个注释:

请注意,要显示在菜单中的项目应该既可见又可访问。

例如,索引视图可以遵循以下几行:

from flask_admin import Admin
from flask_admin import AdminIndexView
from flask_admin import expose, AdminIndexView


class DashboardView(AdminIndexView):

    def is_visible(self):
        # This view won't appear in the menu structure
        return False

    @expose('/')
    def index(self):

        return self.render(
            'admin/dashboard.html',
        )

flask_admin = Admin(app,
    name='Customer Admin',
    template_mode='bootstrap3',
    index_view=DashboardView()
)