Closed lucasvo closed 7 years ago
There's no easy way of doing it right now. But pull requests are welcome!
It's easy to extend: just drop this template to /templates/admin/master.html
{% extends 'admin/base.html' %}
{% block tail_js %}
{{ super() }}
{% if admin_view.extra_js %}
{% for js in admin_view.extra_js %}
<script src="{{js}}"></script>
{% endfor %}
{% endif %}
{% endblock %}
And add this to your ModelView:
class MyModelView(ModelView):
extra_js = ['//cdn.ckeditor.com/4.6.0/standard/ckeditor.js']
Anyway, I agree this would be better to have in flask-admin base templates.
Fixed in #1400
@vgavro I know this is old but I'm getting an error when trying to load a local script from my static dir:
In ModelView: extra_js = [url_for('static', filename='admin/admin.js')]
Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.
It's possible to add extra_js in API doc ?
@alxvallejo if you haven't found a solution yet, checkout this answer. It's also explained in the documentation.
Django offers a neat way to define JS/CSS dependencies that get loaded automatically when rendering the form: https://docs.djangoproject.com/en/1.10/topics/forms/media/
If I wanted to have something similar in flask-admin, I'd have to extend 4 templates:
Or is there an easier way to achieve this? If not, is there general demand for supporting this?