6

I have a Django website in which I use django-tinymce to edit HTML fields with a TinyMCE control.

TinyMCE practically gives me a WYSIWYG way to edit HTML. My question is, can I get access to edit the underlying HTML directly? I was thinking, maybe there's some button I can enbale which will toggle between "WYSIWYG mode" and "raw html mode" in TinyMCE. Is there one? If not, is there any elegant way to edit the HTML?

Ram Rachum
  • 84,019
  • 84
  • 236
  • 374

2 Answers2

12

Simply add the code button to one of the toolbars, e.g. with this configuration for django-tinymce:

TINYMCE_DEFAULT_CONFIG = {
    # your other configuration
    'theme_advanced_buttons3_add': 'code',
}

Here's a list of buttons that are available with the advanced TinyMCE theme

Benjamin Wohlwend
  • 30,958
  • 11
  • 90
  • 100
2

django-tinymce version 3 uses TinyMCE version 5 that requires enabling the code button plugin and adding the code button to toolbar:

TINYMCE_DEFAULT_CONFIG = {
    ...
    'plugins': 'code', # along with other plugins, e.g. 'link lists code'
    'toolbar': 'code', # along with other buttons, e.g. 'bold italic | code'
    ...
}
mrts
  • 16,697
  • 8
  • 89
  • 72
  • 2
    Nothing like waking up in the morning to see an answer to a question you asked over a decade ago :) – Ram Rachum Dec 09 '20 at 05:07
  • 1
    The question is still relevant and the answer may help others :). I spent half an hour digging this up, thought it might save that effort for the next guy/gal! – mrts Dec 09 '20 at 12:52