django模板中的图像(images in django templates)

编程入门 行业动态 更新时间:2024-10-28 22:26:37
django模板中的图像(images in django templates)

我解析图像并显示它。 按照我的意愿,我解析了。 正在解析新闻提要。 在模板中,我想检查条件,如果可用图像意味着它将显示图像,否则它应该在静态文件夹中显示图像。 我需要检查一下我的语法。

模板文件:

{% for i in arr %} <img src="{% if image %}{{i.image}}{% else %}{<img src="/static/img/image.jpeg">}{% endif %}" style="width:100px;height:100px;"> {% endfor %}

以上是我编写的代码,但不显示图像。 请指导我继续

Am parsing images and displaying it. As my wish I parsed. Am parsing news feed. In templates I want to check the condition that if images available means it will show the images otherwise it should show the image in static folder. I need to check my syntax.

Template file:

{% for i in arr %} <img src="{% if image %}{{i.image}}{% else %}{<img src="/static/img/image.jpeg">}{% endif %}" style="width:100px;height:100px;"> {% endfor %}

The above is the code that I have written but the images are not displayed. Please guide me to proceed further

最满意答案

请检查以下必须解决问题的代码:

{% for i in arr %} <img src="{% if i.image %}{{ i.image.url }}{% else %}{{ STATIC IMAGE URL }}{% endif %}" style="width:100px;height:100px;"> {% endfor %}

Please check the following code that must solve your problem:

{% for i in arr %} <img src="{% if i.image %}{{ i.image.url }}{% else %}{{ STATIC IMAGE URL }}{% endif %}" style="width:100px;height:100px;"> {% endfor %}

更多推荐

本文发布于:2023-07-29 20:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319471.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   模板   django   images   templates

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!