Setting TinyMCE configs in Django settings.py

Working with the Django Filebrowser and TinyMCE I have just spent quite a while with an utterly frustrating problem.

I want to set all my my inserted image paths to absolute e.g. /media/uploads/someimge.jpg – in TinyMCE the way to do this is to set “convert_urls”: false

The relevant part of my settings.py file looked like this:

TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,spellchecker,paste,searchreplace",
    'theme': "advanced",
    'theme_advanced_toolbar_location' : "top",
    'theme_advanced_toolbar_align' : "left",
    'theme_advanced_statusbar_location' : "bottom",
    'theme_advanced_resizing' : "true",
    'convert_urls' : "false"
}

But nothing worked and my images were all being inserted as ../../../media/uploads/someimge.jpg

Eventually looking at the generated source of my page I realised that the problem was this was rendering “convert_urls”: “false” it should be rendering “convert_urls”: false

The solution is pretty obvious – but then they usually are:

TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,spellchecker,paste,searchreplace",
    'theme': "advanced",
    'theme_advanced_toolbar_location' : "top",
    'theme_advanced_toolbar_align' : "left",
    'theme_advanced_statusbar_location' : "bottom",
    'theme_advanced_resizing' : True,
    'convert_urls' : False
}

The reason it took me so long to figure out was that I tried to use ‘convert_urls’ : false – which just resulted in syntax error – coming from PHP I’m used to booleans being case insensitive – in Python they aren’t. It also explains why my ‘theme_advanced_resizing’ didn’t work either.