Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask-Admin remove "Home" button

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'))
like image 644
Sean McCarthy Avatar asked Sep 05 '25 03:09

Sean McCarthy


2 Answers

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()
)
like image 69
pjcunningham Avatar answered Sep 07 '25 20:09

pjcunningham


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

like image 22
Sean McCarthy Avatar answered Sep 07 '25 21:09

Sean McCarthy