djangowebtinymcetinymce-pluginsdjango-tinymce

Django-Tinymce not loading


I have included django-tinymce module in my django 3.1 project. However, the tinymce editor disappeared from my pages and I don't know why. When I run the project in my localhost I get a 404 on init_tinymce.js, a folder that is not in my project and not specified in the django-tinymce project.

I hardly touched anything but it suddenly did not show on my pages. Here is the log from my console:

[08/Jun/2021 08:32:26] "GET /letter_head_edit/1/ HTTP/1.1" 200 14367
[08/Jun/2021 08:32:26] "GET /static/django_tinymce/init_tinymce.js HTTP/1.1" 404 179
[08/Jun/2021 08:32:26] "GET /static/django_tinymce/init_tinymce.js HTTP/1.1" 404 179

Here is my settings.py file config:

TINYMCE_JS_URL = os.path.join(STATIC_URL, "js/tinymce/tinymce.min.js")
TINYMCE_JS_ROOT = os.path.join(STATIC_ROOT, "js/tinymce")
TINYMCE_SPELLCHECKER = True

TINYMCE_DEFAULT_CONFIG = {
    "height": "500px",
    "width": "auto",
    "menubar": "file edit view insert format tools table help",
    "plugins": "advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code "
    "fullscreen insertdatetime media table paste code help wordcount spellchecker",
    "toolbar": "undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft "
    "aligncenter alignright alignjustify | outdent indent |  numlist bullist checklist | forecolor "
    "backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap emoticons | "
    "fullscreen  preview save print | insertfile image media pageembed template link anchor codesample | "
    "a11ycheck ltr rtl | showcomments addcomment code",
    "custom_undo_redo_levels": 10,
    "language": "es_ES",  # To force a specific language instead of the Django current language.
}

And finally how I load TinyMCE on my forms. I use model forms for this.

I import it first:

from tinymce import models as tinymce_models

Then use it on one of the models:

content = tinymce_models.HTMLField(blank=True, null=True)

URLs.py:

urlpatterns = [
     
    path('tinymce/', include('tinymce.urls')),
]

Finally, on the template:

<div class="form-row">
      <div class="form-group col-md-12 mb-0">
            {{ form.media }}
        {{ form.content|as_crispy_field }}
      </div>
    </div>

Solution

  • If you don't specifically need to change the default TINYMCE_JS_URL and TINYMCE_JS_ROOT settings, don't set them in your project. Did you include 'tinymce' in your INSTALLED_APPS?