admin_base_template is undefined

Hi all,

I'm using Flask-Admin so that the website url with /admin at the end opens the admin page. However, I'm having issues opening it from a python script. Any ideas what's going on?


@app.route('/admin', methods=["GET", "POST"])
def mesage_post():
     if request.method == 'POST':
        result = request.form
        message= result.get('Message')
        message2= result.get('Message2')
        return render_template("admin/index.html",  result = result,  message = message,  message2 = message2)
        return render_template("admin/index.html")

The main admin page is stored in templates/admin/index.html and typing in the standard url of the website with /admin at the end works fine but using this code which should open the same file at the same URL, I get the error:

2018-02-12 14:32:08,352: jinja2.exceptions.UndefinedError: 'admin_base_template' is undefined

This seems to be on the index.html page itself but why I'm confused as to why it works when opening the page manually?

Index.html extends the main Flask-Admin page:

{% extends 'admin/master.html' %}
{% block head_css %}
{{ super() }}
<link href="{{ url_for('static', filename='admincsstest') }}" rel="stylesheet">
{% endblock head_css %}

<{% block body %}

{{ super() }}

Any help would be appreciated! Thanks.

I think that any view that renders a template that inherits from a Flask admin view needs to do some special stuff to make it work -- check out this Stack Overflow answer.

Thank you very much, but sadly that still doesn't fix it.

I get another error: AttributeError: 'NoneType' object has no attribute 'base_template'

I would guess that you're still missing some argument or property that flask-admin is expecting. Look at the stack trace to determine what it might be and then at the flask-admin docs to see how you might be able to provide it.

I'm afraid we're not really experts on flask-admin, so you may have better luck asking on a more dedicated forum.