Django Tinymce js not loading

3.4k Views Asked by At

hi all Im tryng to integrate a tinymce in a django admin page. I've installed the django-tinymce module (http://code.google.com/p/django-tinymce/) I followed the instructions so these are my files:

settings.py

INSTALLED_APPS = (
    ...
    'tinymce',
)


TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,paste,searchreplace",
    'theme': "advanced",
}
TINYMCE_SPELLCHECKER = False
TINYMCE_COMPRESSOR = False

url.py

urlpatterns = patterns('',
    # Example:
    # (r'^uboPy/', include('uboPy.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
        (r'^admin/', include(admin.site.urls)),
        (r'^tinymce/', include('tinymce.urls')),
)

i have the tinymce's js in a folder in the root called media/js In the model i've this line: text = tinymce_models.HTMLField()

when i run the server i don't get error but when i go in the admin area of my model the tinymce is not loaded. With firebug i see that the tinymce library give a 404 error but the path is correct.. i have some problem in my url.py?

thanks for the help

2

There are 2 best solutions below

0
On

Are you just putting a folder in your project root called media/js? It actually needs to be served somehow from a url somewhere.

The JavaScript file is loaded via your browser, so it needs to be accessible to the internet where all of your other media lives. This part has nothing to do with django, so you shouldn't expect errors or URL issues.

Once you've solved that part, specify the URL where the file can be accessed via the TINYMCE_JS_URL settings parameter.

For example, on my setup, the js is..

TINYMCE_JS_URL = '/media/js/tiny_mce/tiny_mce.js'

With firebug i see that the tinymce library give a 404 error but the path is correct..

Are you saying you can visit this URL path and the JS file loads? What I'm saying is: how is the path correct if it's a 404?

0
On

I found out the django-tinymce documentation is outdated, i.e. partially wrong.

What I discovered is that different versions of tinymce and django-tinymce packages are not compatible.

I solved it adding some variables to my project/settings.py and altering the tinymce directory and file names.

django-tinymce urls.py had some hardcoded paths in it which assumed the directories were named "tiny_mce" when in reality they were named "tinymce", hcen I had to rename them, or change the django-tinymce urls.py.

# project setting.py
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_JS_DIR = os.path.join(STATIC_DIR, "js")
TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")
#TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
#TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")