flask-admin icon indicating copy to clipboard operation
flask-admin copied to clipboard

How to use the flask-admin template outside of the admin views

Open jdejoode opened this issue 9 years ago • 3 comments

I want my login and register pages to have the same layout as the admin pages, but I always get the infamous errors showing that 'admin_base_template' is undefined.

How can I accomplish this (DRY)?

jdejoode avatar Oct 18 '15 19:10 jdejoode

You have to extends from admin/base.html. In example, for Flask-Security you can do this:

{% extends 'admin/base.html' %}

{% block access_control %}
{% if current_user.is_authenticated %}
<div class="navbar-text btn-group pull-right">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
        <i class="glyphicon glyphicon-user"></i>
        {% if current_user.name -%}
        {{ current_user.name }}
        {% else -%}
        {{ current_user.email }}
        {%- endif %}<span class="caret"></span></a>
    <ul class="dropdown-menu" role="menu">
        <li><a href="{{ url_for_security('change_password') }}">Change password</a></li>
        <li><a href="{{ url_for_security('logout') }}">Log out</a></li>
    </ul>
</div>
{% endif %}
{% endblock %}

and your template will have same layout.

ypopivniak avatar Jan 26 '16 16:01 ypopivniak

I'm getting the same error. What was your solution?

nyaboke-nyaribo avatar Jul 14 '22 14:07 nyaboke-nyaribo

It's been a while. I think that overwriting admin/templates/admin/base.html did it.

jdejoode avatar Jul 15 '22 10:07 jdejoode