Search code examples
djangopluginsckeditordjango-mediadjango-ckeditor

image2 django-ckeditor plugin: configure url


I've added the plugin image2 to my django-ckeditor. When I upload the image there are two new lines at the server log:

[Wed Nov 05 14:54:26 2014] [error] WARNING 2014-11-05 14:54:26,419 base 10867 139681117435872 Not Found: /var/www/cms/unicms/media/ck_uploads/roberto/2014/11/05/nfgtt51.jpg
[Wed Nov 05 14:54:26 2014] [error] WARNING 2014-11-05 14:54:26,696 base 10990 139681117435872 Not Found: /nb/var/www/cms/unicms/media/ck_uploads/roberto/2014/11/05/nfgtt51.jpg/

The file it's being correctly uploaded, as it can be seen if I go directly to the image from the browser:

http://myserver/media/ck_uploads/roberto/2014/11/05/nfgtt51.jpg

But the editor is inserting the following in the tags:

<img alt="" src="/var/www/cms/unicms/media/ck_uploads/roberto/2014/11/05/python-3_UYI5FVE.png" />

So that's why I'm getting 404 errors. This is my CKEDITOR configuration in settings.py:

CKEDITOR_RESTRICT_BY_USER = True
CKEDITOR_UPLOAD_PATH = os.path.join(MEDIA_ROOT, 'ck_uploads')
CKEDITOR_CONFIGS = {
    'default': {
        'width': '100%',
        'toolbar': 'full',
        'extraPlugins': 'image2'
    },
    'basic': {
        'width': '100%',
        'toolbar': 'Basic',
    }
}

How can I configure image2 to use settings.MEDIA_URL instead of settings.MEDIA_ROOT? Thanks :-)

Regards,

Roberto


Solution

  • Doing some research about the django-ckeditor configuration, it seems that with some recent update the CKEDITOR_UPLOAD_PATH has passed from absolute to relative https://github.com/shaunsephton/django-ckeditor#id2

    So just changing:

    CKEDITOR_UPLOAD_PATH = os.path.join(MEDIA_ROOT, 'ck_uploads')
    

    by:

    CKEDITOR_UPLOAD_PATH = 'ck_uploads/'
    

    Solved my problem :-)