Dreamer
Dreamer

Reputation: 31

Make Flask-Admin support Bootstrap4

i'm working on a flask application using a template with bootstrap4 , how can i make flask-admin support bootstrap 4 please ?

    admin = Admin(app, template_mode='bootstrap3')
# define UserView
class UserView(ModelView):

    can_view_details = True
    column_exclude_list = ['password', ]
    column_searchable_list = ['email',]

admin.add_view(UserView(User, db.session))

# define RoleView
class RoleView(ModelView):

    can_view_details = True
    column_searchable_list = ['name',]

admin.add_view(RoleView(Role, db.session))

Upvotes: 2

Views: 3531

Answers (1)

pjcunningham
pjcunningham

Reputation: 8046

Update October 2020: Flask-Admin 1.5.7 includes Bootstrap 4!

Flask-Admin now supports Bootstrap 4. From the source code, note parameter template_mode:

class Admin(object):
    """
        Collection of the admin views. Also manages menu structure.
    """
    def __init__(self, app=None, name=None,
                 url=None, subdomain=None,
                 index_view=None,
                 translations_path=None,
                 endpoint=None,
                 static_url_path=None,
                 base_template=None,
                 template_mode=None,
                 category_icon_classes=None):
        """
            Constructor.
            :param app:
                Flask application object
            :param name:
                Application name. Will be displayed in the main menu and as a page title. Defaults to "Admin"
            :param url:
                Base URL
            :param subdomain:
                Subdomain to use
            :param index_view:
                Home page view to use. Defaults to `AdminIndexView`.
            :param translations_path:
                Location of the translation message catalogs. By default will use the translations
                shipped with Flask-Admin.
            :param endpoint:
                Base endpoint name for index view. If you use multiple instances of the `Admin` class with
                a single Flask application, you have to set a unique endpoint name for each instance.
            :param static_url_path:
                Static URL Path. If provided, this specifies the default path to the static url directory for
                all its views. Can be overridden in view configuration.
            :param base_template:
                Override base HTML template for all static views. Defaults to `admin/base.html`.
            :param template_mode:
                Base template path. Defaults to `bootstrap2`. If you want to use
                Bootstrap 3 or 4 integration, change it to `bootstrap3` or `bootstrap4`.
            :param category_icon_classes:
                A dict of category names as keys and html classes as values to be added to menu category icons.
                Example: {'Favorites': 'glyphicon glyphicon-star'}
        """

To use construct your Admin class instance as follows:

admin = Admin(app, template_mode='bootstrap4')

Upvotes: 4

Related Questions