Search code examples
python-3.xflaskflask-admin

How can disable navbar in Flask-Admin?


I want Disable navbar in Flask-Admin. I want to access directly to operation with /admin/something


Solution

  • There's an example in the Flask-Admin Github repository of customizing the layout, Custom Layout.

    In your particular case you need to remove the <nav></nav> html section within the {% block page_body %} Jinja2 block of the base layout template file.

    Create a file menuless-layout.html in your project's templates/admin directory which extends the built-in base layout. Copy and paste the {% block page_body %}{% endblock %} block and delete the <nav></nav> section.

    {% import 'admin/layout.html' as layout with context -%}
    {% extends 'admin/base.html' %}
    
    {% block page_body %}
      <div class="container{%if config.get('FLASK_ADMIN_FLUID_LAYOUT', False) %}-fluid{% endif %}">
    
        <!-- Nav section removed -->
    
        {% block messages %}
        {{ layout.messages() }}
        {% endblock %}
    
        {# store the jinja2 context for form_rules rendering logic #}
        {% set render_ctx = h.resolve_ctx() %}
    
        {% block body %}{% endblock %}
      </div>
    {% endblock %}
    

    Then instruct Flask-Admin to use this template as the base layout:

    # Create admin with custom base template
    admin = admin.Admin(app, 'Example', base_template='admin/menuless-layout.html', template_mode='bootstrap3')