私が間違っていることを見つけることができません(構文エラーであるはずです)。写真が表示されません。「NO FILES」が表示されます。
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 %}