django - 无法从 Django 管理员显示图像
问题描述
我正在尝试查看/显示我在产品模型中上传的图像。产品 html 以查看产品中的内容。
下面是views.py 代码:
def ProductDetailtListView(request, pk=None, *args, **kwargs):
#instance = Product.objects.get(pk=pk)#id
instance = get_object_or_404(Product, pk=pk)
context = {
'object': instance
}
return render(request, 'MainApp/productDetail.html', context)
下面是 models.py 代码:
class Product(models.Model):
title = models.CharField(max_length=120)
description = models.TextField()
price = models.DecimalField(decimal_places=2, max_digits=10, default=39.99)
image = models.FileField(upload_to=upload_image_path, null= True, blank=True)
def __str__(self):
return self.title
def __unicode__(self):
return self.title
这是 productDetailListView.html 页面:
{% load static %}
{{ object.title }} <br/>
{{ object.description }} <br/>
{{ object.image.url }}
<img src="{{ object.image.urls }}" class='img-fluid'/>
解决方案
推荐阅读
- javascript - NSIS - js文件解压需要很长时间
- sql - 请求 sql COUNT 不归零
- java - 基于现有数据以编程方式构建 SQL 插入字符串
- php - PHP中充满奇怪编码字符的页面响应的原因是什么
- laravel - 文件存储 Laravel
- php - 如何在没有活动的情况下使用 volley 将文件路径为“sdcard/file1.pdf”的文件从我的 sdcard 上传到 php 服务器
- blockchain - Exonum 区块链锚定成本
- php - PHP - 如果出现单词,则行高亮修复
- flickity - Flickity 如何使轮播根据图像大小调整大小?
- php - 第 150 行 /app/public/wp-includes/class-walker-nav-menu.php 中传递的参数无效