ModelForm does not display TinyMCE (ReferenceError: tinyMCE not defined)

I have django-tinymce working on admin page. Now, outside the admin page, when I used the model, I expected the TinyMCE editor to be loaded and shown to the user, but this did not happen. All I see is the text area. But it works on the admin page.

from tinymce.models import HTMLField class Punch(models.Model): discussion = HTMLField() class PunchForm(forms.ModelForm): class Meta: model = Punch 

I can see with firebug that the TinyMCE snippet is added to the HTML:

enter image description here

However, I get an error in the console:

 ReferenceError: tinyMCE is not defined 

It doesn’t make sense, why on the admin page there is no problem finding TinyMCE? In addition, I added it even to base.html:

 <script type="text/javascript" src="{{ STATIC_URL }}tiny_mce/tiny_mce.js"></script> 

And the server can also load it:

 [21/Apr/2013 13:42:40] "GET /static/tiny_mce/tiny_mce.js HTTP/1.1" 304 0 

And what could be the problem?

+7
source share
1 answer

Oh dear, what a stupid mistake.

So, I can confirm that I need to define js in base.html , as it was in my question.

 <script type="text/javascript" src="{{ STATIC_URL }}tiny_mce/tiny_mce.js"></script> 

However, this should be in the header, not in the body. The header is initialized first and therefore will no longer be a ReferenceError: tinyMCE is not defined

Hope this helps someone else.

+7
source

All Articles