django-tinymce doesn't show formatting toolbar
Asked Answered
F

1

6

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

Formyl answered 19/4, 2015 at 7:5 Comment(0)
H
1

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.

Honegger answered 20/4, 2015 at 20:28 Comment(2)
OK, but the asker has Django 1.8, you mentioned in your answer 1.4-1.7. Is there something more you want to add to the answer to make it more clear?Ledford
As you can see in the link, I said that django_tinymce/init_tinymce.js is made only for django version 1.4-1.7.Honegger

© 2022 - 2024 — McMap. All rights reserved.