image2 django-ckeditor插件:配置网址

时间:2014-11-05 14:47:39

标签: django plugins ckeditor django-media django-ckeditor

我已将插件image2添加到我的django-ckeditor中。当我上传图像时,服务器日志中有两个新行:

[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/

正确上传文件,因为我可以看到是否直接从浏览器转到图片:

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

但是编辑器在标签中插入以下内容:

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

这就是为什么我会收到404错误的原因。这是我在settings.py中的CKEDITOR配置:

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',
    }
}

如何配置image2以使用settings.MEDIA_URL而不是settings.MEDIA_ROOT?谢谢: - )

此致

罗伯特

1 个答案:

答案 0 :(得分:1)

对django-ckeditor配置进行一些研究,似乎有一些最近的更新,CKEDITOR_UPLOAD_PATH已从绝对传递到相对https://github.com/shaunsephton/django-ckeditor#id2

所以只需改变:

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

由:

CKEDITOR_UPLOAD_PATH = 'ck_uploads/'

解决了我的问题: - )