Django-CKEditor won't render images

我与影子孤独终老i 提交于 2019-12-11 03:24:48

问题


I've installed Django-CKEditor and configurated it for development purposes.

Now I can edit text and save it to db as text field. But with inserting images I have major problems...

I can insert image and it seems to save properly to local host (to correct folder) but when rendering image to preview or text editor I get only broken image picture. Apparently I haven't configured settings.py correctly. Main items from settings.py:

MEDIA_ROOT = ''
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
CKEDITOR_UPLOAD_PATH = 'media/uploads/'
CKEDITOR_UPLOAD_PREFIX = 'media/uploads/'

Also tried similar configuration than django-ckeditor testproject has but faced similar broken rendering images.

I'm using windows environment for development. Django-ckeditor version is 4.0.2

Any ideas what is wrong or where to start solving this?


回答1:


try collecting all static files Use following in shell

python manage.py collectstatic

Look into this link : https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/




回答2:


Found the root cause.

After debugging it found out that django-ckeditor has problems with Windows back-slashes. First I made my own correction but finally also found out that this has been already reported and correction proposal also made but not yet merged to master branch:

Fixing trouble with backward slashes in Windows




回答3:


Use django-vckeditor - it is easier to install and configure. For files uploaded via FTP or existing thumbnails will be created automatically.




回答4:


I had correct urls but images were still not rendering until I remembered to mark the html as safe in the template (i.e. {{my_model.my_text_field|safe}})



来源:https://stackoverflow.com/questions/18894044/django-ckeditor-wont-render-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!