4

Im trying to implement TinyMCE on Django, i have successfully implement it on admin page using settings like this :

admin.py:

class TinyMCEAdmin(admin.ModelAdmin):
    class Media:
            js = ('/media/js/tiny_mce/tiny_mce.js', '/media/js/tiny_mce/textareas.js',)

settings.py :

TINYMCE_JS_ROOT = '/media/js/tiny_mce/'
TINYMCE_JS_URL = '/media/js/tiny_mce/tiny_mce.js'

then when i try to implement it on my form(non-admin) :

forms.py:

from tinymce.widgets import TinyMCE

class Foo(forms.Form):
    title       = forms.CharField(max_length = 100)
    content     = forms.CharField(widget = TinyMCE())

When i see the result, it just showing plain html textarea, then i hit "F12" on Chrome, then it says : 'Uncaught reference error: tinyMCE is not defined'.

How do i fix that error? thx guys

2 Answers 2

4

Looking at the documentation, if you are using TinyMCE in your form outside of the admin, you need to tell it to include the JS/CSS required to render TinyMCE manually. So in your base template (or somewhere similar) you need to add:

<head>
    ...
    {{ form.media }}
</head>

or you could simply manually load the js:

<head>
   <script src="{{ MEDIA_URL }}js/tiny_mce/tiny_mce.js"></script>
   <script src="{{ MEDIA_URL }}js/tiny_mce/textareas.js"></script>
</head>

but the former is probably easier

Sign up to request clarification or add additional context in comments.

Comments

0

Looks like the file tiny_mce.js has not been loaded in this case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.