图像未出现-django ckeditor

时间:2019-01-19 12:43:37

标签: python django ckeditor

我在ckeditor中上传了图片,但没有出现,因为图片的路径为

http://127.0.0.1:8000/blog/post/hello-23-1547897944/uploads/2019/01/19/southside.jpg

但是图像正在上传到该文件夹​​: enter image description here

enter image description here enter image description here

settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main',
    'contact',
    'widget_tweaks',
    'ckeditor',
    'ckeditor_uploader',
]

CKEDITOR_UPLOAD_PATH = 'uploads/'

urls.py:

urlpatterns = [
    ...
    path('ckeditor/', include('ckeditor_uploader.urls')),
]

models.py:

from ckeditor_uploader.fields import RichTextUploadingField

class Post(models.Model):
    title = models.CharField(max_length=150, db_index=True)
    slug = models.SlugField(max_length=150, blank=True, unique=True)
    body = RichTextUploadingField(blank=True, db_index=True)

我认为问题出在settings.py

对不起,我的英语不好,但我希望你能理解我的问题。

1 个答案:

答案 0 :(得分:0)

我只添加:

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)  

到我的urls.py并成功!