django-summernote
django-summernote copied to clipboard
Problems using "iframe": False with the admin widget
First of all, thanks for making an easy Django+Summernote integration happen!
I've spent several hours today trying to set up the Summernote widget on the admin site without using iframes. This was caused by a series of issues:
- Using Django admin's own jQuery is not (trivially) possible because Summernote's dependencies (bootstrap.js, jquery.widget.js) expect jQuery to be globally available as
$orjQuery. - I've tried adding jQuery to the widget's javascripts but because Django has its own opinion on in what order assets should be loaded, some Summernote js ends up extending Django's jQuery, some others the one I brought in. The solution was to remove adding js assets from the widget and add back "manually" using a modified
admin/base.htmltemplate (see below). - There is also a small bug that prevents django-summernote from initializing when jQuery is non-standard global.
- The bundled version of summernote.js itself seems to break with non-standard jQuery, I had to upgrade to the latest.
- Bringing Bootstrap.css into the admin is not a great idea, many things will start looking differently. Fair enough, added
SUMMERNOTE_THEME = "lite".
There might be an easy way to get all this working but it's not obvious from the documentation/source code.
I'm using the following settings:
SUMMERNOTE_CONFIG = {
"iframe": False,
"jquery": "summernoteJQuery",
}
SUMMERNOTE_THEME = "lite"
...and admin/base looks like this:
{% extends "admin/base.html" %}
{% load static %}
{% block extrahead %}
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="{% static "summernote/summernote-lite.min.js" %}"></script>
<script>window.summernoteJQuery = jQuery.noConflict(true);</script>
{% endblock %}
But all this only works with my hacky fork: https://github.com/salomvary/django-summernote
@salomvary Why does it only work with your fork?
Because of the reasons mentioned in the description of this issue above?
@salomvary I apologize, I am totally blanking on this one. Is this something I brought up?
@salomvary Hello. Thanks for your fork, summernote now works without an iframe. But there is one problem: photos are not loaded from the file system. Do you know what the problem might be?
@salomvary Hello. Thanks for your fork, summernote now works without an iframe. But there is one problem: photos are not loaded from the file system. Do you know what the problem might be?
No, unfortunately I don't know, I don't use the widget with photos in any way.
I've found another issue where dynamically added Summernote widgets as part of form inlines do not properly get initialized. Workaround here: https://github.com/salomvary/django-summernote/commit/ddd27373813001b061f328b1e9d218e51b0b8881