找不到我做错了什么(我想应该是一些语法错误)。我的图片不显示。我收到“没有文件”。
html
<!-- RECENTLY ADDED FILES -->
<div class="buttom-box floatleft">
<h3>Recently Added Files</h3>
<p>New class papers. Now you can enjoy and study them</p>
<br>
{% if recent_files %}
{% for file in recent_files %}
<img src="{{ MEDIA_URL }}{{ file.image }}" alt="Sample 1" width="125" height="125" />
{% endfor %}
{% else %}
<p>NO FILES</p>
{% endif %}
</div>
视图.py
def index(request):
recent_files = FileDescription.objects.all()
context_instance=RequestContext(request)
return render_to_response('index.html',
{'recent_files':recent_files,},
context_instance,
)
用于文件描述的 MySQL:
mysql> SELECT * FROM school_filedescription;
+----+------------+--------------+-----------+------------------+-----------+------------------+---------------------+---------------------+-----------------------------+
| id | subject_id | subject_name | file_type | file_uploaded_by | file_name | file_description | file_creation_time | file_modified_time | image |
+----+------------+--------------+-----------+------------------+-----------+------------------+---------------------+---------------------+-----------------------------+
| 1 | 1 | Math 140 | class | rrr | lalala | lalala | 2012-08-23 12:12:12 | 2012-08-23 12:12:12 | files/rrr/class/smart.jpg |
| 2 | 1 | Math 140 | class | rrr | ,s,s,s | s msms | 2012-08-23 12:32:39 | 2012-08-23 12:32:39 | files/rrr/class/smart_1.jpg |
+----+------------+--------------+-----------+------------------+-----------+------------------+---------------------+---------------------+-----------------------------+
2 rows in set (0.00 sec)
但是,其他页面中的此代码工作正常
其他页面:
{% extends "base.html" %}
{% block main-menu %}
<div class="contentarea">
<img src="{{ MEDIA_URL }}{{ picture.image }}"/>
</div>
{% endblock %}