Django-tinymce does not display formatting toolbar

TL DR - Tinymce formatting toolbar is not displayed. One line of django html generated seems suspicious, but I'm not sure why it is where it is. These are python 3.4 and django 1.8.

I have done this:

settings.py

I use django-tinymce defaults.

INSTALLED_APPS = ( ..., 'django.contrib.staticfiles', ..., 'tinymce', ... ) 

urls.py

 ... url(r'^tinymce/', include('tinymce.urls')) ... if settings.DEBUG: urlpatterns += patterns('django.views.static', (r'^media/(?P<path>.*)', 'serve', {'document_root': settings.MEDIA_ROOT}),) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

models.py

 from tinymce.models import HTMLField class BlogEntry(models.Model): ... #article_body = HTMLField() article_body = models.TextField() 

(Documents suggest HTMLField. Other sources suggest TextField. The results remain the same.)

form.py

 from tinymce.widgets import TinyMCE class BlogEntryForm(forms.ModelForm) article_body = forms.CharField( widget=TinyMCE(#mce_attrs={ #'plugin_preview_pageurl': reverse('tinymce-preview', "blog")}, attrs={ 'cols': 80, 'rows': 30, 'placeholder': 'contenu', 'class': 'lkz-input'}),) 

template

 {% extends "kernel/base.html" %} {% block extra_head %} <!-- before media --> {{ entry.media }} <!-- after media --> <script type="text/javascript" src="{% url "tinymce-js" "tinymce" %}"></script> <!-- end --> {% endblock extra_head %} {% block content %} <form method="post" action=""> {% csrf_token %} ... {{ entry.article_body.errors }} <label for="{{ entry.article_body.id_for_label }}" ></label> {{ entry.article_body }}<br> ... </form> 

which, I think, is a set of things that I needed to do. But the text box looks like a text box.

One rather strange thing (and the main suspect) is that I see that this HTML is being served:

 <!-- before media --> <script type="text/javascript" src="/static/tiny_mce/tiny_mce.js"></script> <script type="text/javascript" src="/static/django_tinymce/init_tinymce.js"></script> <script type="text/javascript" src="/static/{% media %}/tiny_mce/tinymce.min.js"></script> <!-- after media --> <script type="text/javascript" src="/tinymce/js/textareas/tinymce/"></script> <!-- end --> 

/static/{% media %}/ on line 3 is clearly incorrect, although I don’t see where it comes from. The closest bit of the source I found is tinymce/settings.py , which is not identical (has no "min").

Fwiw, in case I configured it incorrectly, I have the following values:

 STATIC_PATH = os.path.join(BASE_DIR,'static') STATIC_ROOT = '' STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' 

side question

Tinymce docs (not django-tinymce) offer a selection of tinymce from a CDN. Django-tinymce packs it. Does anyone know what the benefit of this could be (besides local debugging)?

+6
source share
1 answer

I have the same problem and the same configuration as yours, you should read in the browser console.

I get:

 Uncaught TypeError: $ is not a function (anonymous function) @ init_tinymce.js:18 (anonymous function) @ init_tinymce.js:38 

https://github.com/aljosa/django-tinymce/tree/master/tinymce/static/django_tinymce Made for 1.4-1.7

Edit:

I found a solution to my problem, try to see if it works for you, edit the init_tinymce.js file

 # at the begging of the file -(function ($) { +$(document).ready(function() { # at the end -}(django.jQuery)); +}); 

You should also comment on TINYMCE_COMPRESSOR = True or set it to False in setting.py .

TINYMCE_COMPRESSOR throws other js-errors if it is allowed.

+1
source

Source: https://habr.com/ru/post/985448/


All Articles