[英]Django not showing images in editor (404 error)
I'm try create post and add to this post images.我正在尝试创建帖子并添加到此帖子图像。 And i'm use for this Django-summernote in Django 3.0.
我在 Django 3.0 中使用这个 Django-summernote。 Picture upload to folder on hard disk, but not showing in editor.
图片上传到硬盘上的文件夹,但没有显示在编辑器中。 Console show 404 Error.
控制台显示 404 错误。 Please, give me advice how to fix it?
请给我建议如何解决它? Thank you!
谢谢!
settings.py设置.py
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"
X_FRAME_OPTIONS = 'SAMEORIGIN'
SUMMERNOTE_THEME = 'bs4' # Show summernote with Bootstrap4
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
urls.py网址.py
urlpatterns = [
path('admin/filebrowser/', site.urls),
path('summernote/', include('django_summernote.urls')),
path('admin/', admin.site.urls),
path('', include('blog.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
models.py模型.py
class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
image = models.ImageField(upload_to="", blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def get_absolute_url(self):
return "/api/article/%i/" % self.id
def __str__(self):
return self.title
Check following stuffs:检查以下内容:
1. DEBUG = True in your settings 1. DEBUG = True在您的设置中
2.Post table in your database whether image field have any value 2.在您的数据库中发布表,图像字段是否有任何值
3.if it is a uploaded file nor a static file so in your template write: 3.如果它是上传的文件,也不是 static 文件,那么在您的模板中写入:
\and add post_object in view context
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.