Search code examples
pythonflaskflask-admin

Disable caching in custom views in Flask Admin


I want to disable cahce in Flask-Admin panel, where i displaying some images. For exmaple, i have 1 image in my DB (actually, just uri to an image). If i delete this image, and then upload a new one, the cache will show me deleted image. To escape this moment, i need disable caching. But, also, i want disable it on all Flask-Admin pages.

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

{% block head_meta %}
{{super()}}
    <meta http-equiv='cache-control' content='no-cache'>
    <meta http-equiv='expires' content='0'>
    <meta http-equiv='pragma' content='no-cache'>
{% endblock head_meta %}

I know if i save code above as index.html, it applies only to index admin page panel. But, as i also said above, i want to disable caching on all pages.


Solution

  • Found some information about it. If you want to edit your CUSTOM view, you should add these variables:

    list_template = 'list.html'
    create_template = 'create.html'
    edit_template = 'edit.html'
    

    Where list.html responsible for list with all your records and so on.

    Also, you should create template, where you put all your code to append to existing Flask-Admin. In my case, it looks like this:

    {% extends 'admin/model/list.html' %}
    
        {% block head_meta %}
            <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
            <meta http-equiv="Pragma" content="no-cache" />
            <meta http-equiv="Expires" content="0" />
            {{ super() }}
        {% endblock head_meta %}
    

    above is example of disabling cache on page where all records are show