Reputation: 1844
according to the flask-admin docs I can extend the main flask-admin dashboard by creating the file templates/admin/index.html
and extending admin/master.html
. The HTML would look like this:
{% extends 'admin/master.html' %}
{% block body %}
<h1>HELLO</h1>
{% endblock body %}
But i can't find any information on how to extend the model CRUD pages: List, Edit and Create. I need to extend the Create and Edit User page so i can add js code to the form template.
Is there a template where i can extend just like admin/master.html
example?
Upvotes: 5
Views: 4274
Reputation: 7665
As for DOC, this is the default command:
admin = Admin(app, name='microblog', template_mode='bootstrap3')
Add your own CSS here /static/css/main.css:
{% block head_css %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css', _external=True) }}" ></link>
{% endblock %}
Upvotes: 0
Reputation: 1844
Just found it in flask-admin docs. I had to create templates/edit_user.html
and templates/create_user.html
. For list_users
is also the same, theres is an example in the docs.
In edit_user.html
{% extends 'admin/model/edit.html' %}
{% block body %}
<h1>User Edit View</h1>
{{ super() }}
{% endblock %}
In create_user.html
{% extends 'admin/model/create.html' %}
{% block body %}
<h1>Create View</h1>
{{ super() }}
{% endblock %}
and then add this to the User model View:
class UserView(ModelView):
edit_template = 'edit_user.html'
create_template = 'create_user.html'
admin.add_view(UserView(User, db.session))
Upvotes: 6