python - 图像不出现 - django ckeditor
问题描述
我在 ckeditor 中上传图像,但它没有出现,因为图像的路径是
http://127.0.0.1:8000/blog/post/hello-23-1547897944/uploads/2019/01/19/southside.jpg
设置.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/'
网址.py:
urlpatterns = [
...
path('ckeditor/', include('ckeditor_uploader.urls')),
]
模型.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
对不起,我的英语不好,但我希望你能理解我的问题。
解决方案
我只补充:
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 并且它有效!
推荐阅读
- python - 使用 python 或 R 将邻接矩阵转换为 torch_geometric.data.Data 格式
- php - 在 OpenBSD 上将 PHP 连接到 Postgresql
- spring-boot - 带有外键的 Spring Data Rest 插入
- ruby-on-rails - 响应中的“Access-Control-Allow-Credentials”标头的值为“”,必须为“真”
- r - st_contour - 应该使用 aes 创建映射
- java - Project Loom 虚拟线程会提高并行流的性能吗?
- javascript - Nodemailer 错误(错误:queryA EREFUSED)
- mysql - docker-compose,为什么后端容器和db容器没有连接?
- c# - 如何使用将 JSON 数据从 ASP.NET MVC 视图传输到 JavaScript JSON?
- pepper - 辣椒模拟器可以将音频用于语音吗?