python - 如何使用 python django 在 html 中显示图像?

标签 python html django

我将图像路径保存在数据库中,例如“Image/upload/imageOne.jpg”并将图像文件夹保存在静态目录中,然后我想使用此标签在 html 中显示此图像:

<img src="{% static '{{ product.productImagePath }}' %}" alt="{{ product.productName }}" width="800px" height="300px">

但是我有错误并且找不到路径,只是显示 alt 如何修复它? 感谢您的帮助

最佳答案

试试这个

{% load static %}

<img src="{% get_media_prefix %}{{ product.productImagePath }}" alt="{{ product.productName }}" width="800px" height="300px">

关于python - 如何使用 python django 在 html 中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44204281/

相关文章:

python - Tensorflow 对象检测 API : how to create tfrecords with images not containing any labels (hard negatives)?

html - 固定标题未固定到页面顶部

django - 如何在发生这种情况的字段附近的模板中打印 ValidationError?

html - 如何阻止占位符转换回来? (CSS)

python - Django 中的显示表单不基于模型/表单

html - 在 Chrome PDF 查看器中加载时 PDF 链接卡住

python - Nodejs服务器,使用Ajax在html客户端中从Python获取JSON数据

python - 在自定义位置查找 conftest.py

python - 对象不匹配

JavaScript 不会计算我的结果并将其输入回我的表单中