Flask-Admin remove "Home" button

Question:

How do I remove the “Home” button in Python’s Flask-Admin library?

enter image description here

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'))
Asked By: Sean McCarthy

||

Answers:

I figured out a way of at least changing the name from the default “Home”.

My new name is ‘NOT HOME’ in the code below. This is a start…

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')
)

enter image description here

Answered By: Sean McCarthy

Flask-Admin BaseView has a method is_visible(self), the source code has a note:

Please note that item should be both visible and accessible to be displayed in menu.

For example, an index view could be along the following lines:

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()
)
Answered By: pjcunningham

Maybe a little hacky but very simple; just add the line:

flask_admin._menu = flask_admin._menu[1:]

This will just remove the first item, which is the home button. The problem I had with the other solutions is that it doesn’t only remove the home button but also the home view. This solution only removes the home buttom.

Answered By: Peter Van 't Zand
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.