Search code examples
djangotinymcewysiwygdjango-tinymce

Installing TinyMCE on Django (And using it on forms)


Hi Im trying to install TinyMCE on a Django project and Im totally lost about static files, MEDIA, and the world itself. I want to use TinyMCE in one of the fields of a form:

class MovieForm(forms.ModelForm):
    class Meta:
        model = Movie
        fields = ['title', 'language', 'description']
        widgets = {
            'languages': forms.SelectMultiple(),
            'description': TinyMCE({'cols':80, 'rows':30}),
        }

I installed django-tinymce pip install django-tinymce

Then I added it to the installed apps

INSTALLED_APPS = (
   ...
  'tinymce',
   ...
)

And then added the urls in my project urls.py

urlpatterns = patterns('',
    ...
    (r'^tinymce/', include('tinymce.urls')),
    ...
)

Great. So what do I do next? I read the Configuration part on http://django-tinymce.readthedocs.io/en/latest/installation.html#configuration but I dont get it. Should I add TINYMCE_JS_URL = os.path.join(MEDIA_URL, "path/to/tiny_mce/tiny_mce.js") to my project settings.py? Where do I put tiny_mce.js? Should I configure MEDIA_URL somewhere? Would be awesome if someone can point me in the right direction.
Thanks! :)


Solution

  • I figured this, so I'm posting an answer in case anyone else comes across this.

    I read more in details the documentation on Static files (https://docs.djangoproject.com/en/1.10/howto/static-files/), and read the related section of the great book Tango with Django (http://www.tangowithdjango.com/).

    That helped me to understand the MEDIA and STATIC setup I needed to get right in order to get working TinyMCE with Django. tiny_mce.js went to the static files folder (specifically to static/tiny_mce/).

    The settings.py of Tinymce check if static is confidured, and points there to get the needed files. Tadaa! It works! Hopefully it will help someone!