【发布时间】:2013-07-04 04:07:59
【问题描述】:
如果我把我的图像放在/media/ 文件夹中,它就不起作用。但如果我将它们放在“/static/”文件夹中,它就可以工作。
{% extends 'base.html' %}
{% block contain %}
<h1>New Report</h1>
<form id="create" method="POST" action="" enctype="multipart/form-data">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Confirm">
</form>
{% for report in reports %}
<P> {{report.title}} </P> <br>
<img src="{{STATIC_URL}}<name of the image>" width='100px' height='100px'> =====> I can see the image
<img src="{{MEDIA_URL}} <name of the image>" width='100px' height='100px'> =====> I cant see the image
<img src="/static/<name of the image>" width='100px' height='100px'> =====> I cant see the image
<img src="/media/<name of the image>" width='100px' height='100px'> ====>>>> I cant see the image
{% endfor %}
{% endblock %}
【问题讨论】:
-
你如何部署你的 django 应用程序?
-
但是我的图片不是静态文件。我的图像是来自我的报告模型的图像。当我将图像放入“媒体”文件夹时,我看不到图像,但是当我在“静态”文件夹中使用该图像时,我可以看到图像。真的很奇怪。
-
这是一个静态文件。您的报告模型 ImageField 只是该文件的链接。看看我的回答。 Django 或您的网络服务器可能不知道您的媒体文件夹
-
如果它是来自您的报表模型的图像,只需直接调用它,django 就会为您填写链接。
标签: python django image templates