【问题标题】:Variable image paths in xhtml2pdf with djangoxhtml2pdf中的可变图像路径与django
【发布时间】:2021-06-26 12:03:17
【问题描述】:

我需要显示具有可变路径的图像,因为用户输入的图像.. 如果我提供像 <img height='200px' src="http://127.0.0.1:8000/media/images/photo.jpeg" alt="Image of student"> 这样的网址,它可以工作,但是,当我将其更改为<img src="{{ result.image_of_student.url }}" alt="Image of student"> 时,它就不起作用了

我该如何进行这项工作,因为每个网址都不同。 在教程中,他们使用了<img src={{ result.image_of_student.path}} alt="Image of student"> 这对他们有用,但对我无效

【问题讨论】:

  • 我建议在某处打印 "{{ result.image_of_student.url }}" 并查看该变量的值。也许result 是空的......
  • 不,其他所有内容都正确显示,并且 url 也显示在 html 中。它不会仅显示在 pdf 中 @hansTheFranz

标签: django xhtml2pdf


【解决方案1】:

改成<img class='image' height='200px' src='{{result.image_of_student.path}}' alt="Image of student">

添加单引号或双引号即可!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 2010-11-10
    • 2022-11-22
    • 2012-01-26
    • 2014-03-31
    相关资源
    最近更新 更多