Dear All,
I would like to know, is there any way to Is there any way to extend template in flask-admin folder?
For example, I would like to change the behavior of admin/lib.html, how can I extend the out of the box lib.html?
I have tried to copy the lib.html file to templates/admin/lib.html on my application folder and try to use
{% extends 'admin/lib.html' %}
Then exception
RuntimeError: maximum recursion depth exceeded
Was thrown out, looks like system tends to extend lib.html from itself.
But actually what I would like to implement is to extend the file lib.html under flask-admin folder.
Any suggestion on this?
Thanks.
Not an expert, but that sounds like a way I did something similar with flask-appbuilder's admin. One thing that this error reminded me of is the fact that jinja evaluates child templates before parents: http://jinja.pocoo.org/docs/dev/faq/#my-macros-are-overridden-by-something. Not sure if that suggests anything.
You created an infinite loop, because your template is extending itself. Of course, that's not what you want.
Instead, have a different name for your template so that admin/lib.html doesn't resolve to your own file, but to the one you want to extend.
However, I found no way so far to override the macro files. It seems you can only override files if you can put there name in the code so that they get called. So you can change the master template file, because flask.Admin(...) constructor provides a base_template parameter. I find that rather limiting.
This is tricky, because render_fields is something we need to get into the internals of. And lib.html houses render_fields macro.
And the issue is, admin/lib.html is a hard link in the edit/detail/etc templates. So it compounds the problem.
i had the same problem with extending admin/model/row_actions.html
i created row_actions_custom.html with my custom row action macro "duplicate_row"
then in list.html template i imported this with
{% import 'row_actions_custom.html' as row_actions_custom with context %}
you can use this in jinja2 {% row_actions_custom.duplicate_row() %}
or in ModelView by
column_extra_row_actions = [
TemplateLinkRowAction('row_actions_custom.duplicate_row', gettext('Duplicate Record'))
]