【问题标题】:Image is not shown in django template,图像未显示在 django 模板中,
【发布时间】:2021-12-10 16:20:22
【问题描述】:

我有一个 django 模板,我在其中发送图像实际上是用于电子邮件。它仅在我保留整个网址(如 abc.com/images/a.png)时才有效。 我给他发了这样的图片:

{
 'picture':picture.url
}

这是我用于电子邮件模板的模板代码:

<img src="{{picture}}" alt="image" width="200" height="200" >

我错过了什么吗?因为它只有在我保留整个网址时才有效?

【问题讨论】:

    标签: python django django-views django-templates


    【解决方案1】:

    要构建绝对 URL,您可以在视图中使用 request.build_absolute_uri(picture.url)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-16
      相关资源
      最近更新 更多