htmldjangodjango-tinymce

Integrating TinyMCE to Django


So i have been trying to use tinymce on my django project but i kept getting: ImportError: cannot import name 'TinyMCE' from 'tinymce' and Cannot find reference TinyMCE in init.py

The very few articles online talks about integrating tinymce with django admin but i'm trying to integrate it with my django forms.

pip installed django-tinymce

settings.py:

INSTALLED_APPS = [ 'tinymce',]

urls.py:

path('tinymce/', include('tinymce.urls')),

models.py:

from tinymce.models import HTMLField

container_description = HTMLField()

forms.py

from tinymce import TinyMCE


class TinyMCEWidget(TinyMCE):
    def use_required_attribute(self, *args):
        return False


class ContainerForm(forms.ModelForm):
    container_serial_number = forms.CharField(widget=forms.TextInput(attrs= 
                          {'placeholder': 'Enter serial number'}))
    container_description = forms.CharField(required=False, 
                          widget=TinyMCEWidget(attrs={'placeholder': 'Enter 
                          description'}), max_length=100)

Followed instructions online for setting up but i still got ImportError. And what else am i supposed to do to set TinyMCE up?


Solution

  • You need to replace:

    from tinymce import TinyMCE
    

    with:

    from tinymce.widgets import TinyMCE
    

    as per the example in the documentation.