【发布时间】:2021-10-17 00:42:00
【问题描述】:
我目前正在使用jinja 在 HTML 中加载一个对象,如下所示
<span> {{ object.name }} </span>
<img src = "{{ object.image }}" >
image 字段是数据库中的 ImageField。图片网址如下所示
http://127.0.0.1:8000/uploads/testimage.png
如何在<img> 标签中正确渲染图像?
【问题讨论】:
-
<img src="{{ object.image.url }}" > -
返回以下问题:
The 'image' attribute has no file associated with it. -
那么您需要保护图像,使其仅在
object.image真实时才呈现。
标签: html django django-models jinja2