Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-tinymce doesn't show formatting toolbar

TL;DR - Tinymce's formatting toolbar doesn't show. One line of django-generated html seems suspect, but I'm not sure why it is where it is. This is python 3.4 and django 1.8.

I've done this:

settings.py

I'm using the django-tinymce default values.

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()

(The docs suggest HTMLField. Other sources suggest TextField. Results are the same so far.)

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 the set of things I needed to do. But the textfield just looks like a textfield.

One rather peculiar thing (and prime suspect) is that I see this HTML 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 -->

The /static/{% media %}/ in line 3 is clearly wrong, though I don't see where it comes from. The closest bit of source I've found is tinymce/settings.py, which is not verbatim identical (doesn't have the 'min').

Fwiw, in case I've configured this incorrectly, I currently have these 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

The tinymce docs (not django-tinymce) propose fetching tinymce from a CDN. Django-tinymce packages it. Anyone know what the advantage of that might be (besides local debugging)?

like image 855
jma Avatar asked Apr 19 '15 07:04

jma


1 Answers

I have the same problem and same configuration as yours, you should read in 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 Is made for 1.4-1.7

Edit:

I found a solution to my problem, try and see if it's working for you, edit file init_tinymce.js

# at the begging of the file
-(function ($) {
+$(document).ready(function() {

# at the end
-}(django.jQuery));
+});

Also you have to comment TINYMCE_COMPRESSOR = True or configure it to False in setting.py .

TINYMCE_COMPRESSOR will throw other js errors if is enabled.

like image 190
Valentin Olaru Avatar answered Oct 06 '22 01:10

Valentin Olaru