Tinymce Editor for Django Project

Verdy Evantyo
Analytics Vidhya
Published in
2 min readJun 4, 2020

Hey guys! This time i want to share about tinymce on django project. Tinymce allows admin user to add some data in html form. Let’s get started!

Tinymce

Tinymce installation

For the installation, open your terminal and run this code :

pip3 install django-tinymce4-lite

Next is open your setting.py and add ‘tinymce’ on your INSTALLED_APPS. Still on settings.py. go to the bottom and type this code :

Tinymce setup

TINYMCE_DEFAULT_CONFIG = {
'cleanup_on_startup': True,
'custom_undo_redo_levels': 20,
'selector': 'textarea',
'theme': 'modern',
'plugins': '''
textcolor save link image media preview codesample contextmenu
table code lists fullscreen insertdatetime nonbreaking
contextmenu directionality searchreplace wordcount visualblocks
visualchars code fullscreen autolink lists charmap print hr
anchor pagebreak
''',
'toolbar1': '''
fullscreen preview bold italic underline | fontselect,
fontsizeselect | forecolor backcolor | alignleft alignright |
aligncenter alignjustify | indent outdent | bullist numlist table |
| link image media | codesample |
''',
'toolbar2': '''
visualblocks visualchars |
charmap hr pagebreak nonbreaking anchor | code |
''',
'contextmenu': 'formats | link image',
'menubar': True,
'statusbar': True,
}

Next is go to your urls.py and type a path for tinymce :

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

Last is go to your models.py and type ‘from tinymce import HTMLField’ on the top and inside your model if you want to add HTML form on your model type :

content = HTMLField()

Next is run makemigrations and migrate and then try to runserver and open djangoadmin and you will get like this :

As you can see, you can type in html form, even adding some photos or videos, font styling, equations and many more. Thank you!

--

--

Verdy Evantyo
Analytics Vidhya

Future data analyst, python enthusiast from Indonesia