我将图像的路径保存在数据库中,如' image /upload/imageOne.jpg‘,并将图像文件夹保存在静态目录中,然后我想用以下标签在html中显示此图像:
<img src="{% static '{{ product.productImagePath }}' %}" alt="{{ product.productName }}" width="800px" height="300px">但是我有错误,找不到路径,只显示alt,如何修复它?感谢你的帮助
发布于 2017-05-26 23:22:25
试试这个
{% load static %}
<img src="{% get_media_prefix %}{{ product.productImagePath }}" alt="{{ product.productName }}" width="800px" height="300px">发布于 2017-05-26 22:41:23
在没有静态的情况下尝试:
<img src="{{ product.productImagePath }}" alt="{{ product.productName }}" width="800px" height="300px">发布于 2017-05-26 22:45:38
假设您使用apache提供页面服务,请确保图像目录也位于'www‘文件夹中,否则如果不更改httpd配置它将无法访问,其他服务器可能会自动指向'htdocs’文件夹。
阅读这篇Djanjo文档可能会对您有所帮助:
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/#serving-files
https://stackoverflow.com/questions/44204281
复制相似问题