【发布时间】:2018-03-22 18:30:29
【问题描述】:
我无法显示 url 类型的图像。 我写在product.html
<body>
{% for product in products.all %}
<h4> {{ product.product_title }}</h4>
<img src="{% static product.image }} %}"/>
<p> {{ product.body }} </p>
{% endfor %}
</body>
在models.py中
class Product(models.Model):
product_title = models.CharField(max_length=250)
image = models.TextField()
body = models.TextField()
在views.py中
def product(request):
products = Product.objects.order_by('product_title')
return render(request, 'registration/product.html',{'products':products})
从管理站点,我添加了 product_title&image&body。 图片的网址是
<a href="https://xxxxxx" target="_blank" rel="nofollow">
<img border="0" width="120" height="60" alt="" src="https://wwwyyyyyyyyyyyy"></a>
<img border="0" width="1" height="1" src="https://wwwzzzzzzzzzz" alt="">
通过使用谷歌控制台,加载资源失败:服务器响应状态为 404(未找到)在控制台中。 在 Elements 中,img 标签就像
<img src="/static/wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww">
如何显示图片?img tag & src的方式我写错了吗?
【问题讨论】:
-
上传的图片不是静态文件。
-
@DanielRoseman 我听不懂你在说什么。你能告诉我更多细节吗?