Tiny MCE popups blank in Django admin

Cato Johnston picture Cato Johnston · Feb 21, 2009 · Viewed 11.6k times · Source

I have got tinyMCE working in the django admin, but all the popups are blank (eg. edit HTML, add image)

The paths to the popup html pages all exist in the right places

http://thatch.media/js/tiny_mce/themes/advanced/source_editor.htm?mce_rdomain=thatch

The permissions are set to 777 on the whole js folder

This is my Model

class Page(models.Model):
    title = models.CharField(max_length=200)
    ...

    class Admin:
        js = ('js/tiny_mce/tiny_mce.js', 'js/textareas.js')

Any Ideas?

Answer

ejucovy picture ejucovy · Sep 13, 2011

I ran into this problem too, using an Amazon S3 bucket to store static media including the TinyMCE javascript.

To be more explicit -- your static media must be on a subdomain of your primary site. So, if your site is running at foo.bar.com -- your static media must be on something like static.foo.bar.com -- note that static.bar.com and static-foo.bar.com will NOT be okay. (If your site is on bar.com then static.bar.com is fine.)

So, once you have your static media served out of a subdomain (for S3 see Amazon S3: Static Web Sites: Custom Domain or Subdomain which helped me) you then need to set the document.domain in javascript in two places:

1) In tiny_mce_popup.js

2) In tiny_mce.js before anything else, or, alternatively, in your main page's rendered HTML in a script tag somewhere before the tiny_mce.init() call occurs. (I found it more expedient to hack up tiny_mce.js and reupload it to S3, rather than mucking around with django-tinymce's widget rendering.)

You need to set document.domain to the domain of the MAIN SITE in both places: so, for a site at foo.bar.com with static media at static.foo.bar.com you will need to set document.domain = "foo.bar.com"

This should prevent any security exceptions in the browser, and everything will now work right.