gpt4 book ai didi

html - 图像不显示。 Django

转载 作者:行者123 更新时间:2023-11-28 02:04:52 25 4
gpt4 key购买 nike

找不到我做错了什么(我猜应该是语法错误)。我的照片没有显示。我得到“没有文件”。

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>

View .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 for FileDescription:

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 %}

最佳答案

尝试将最近的文件参数添加到您的请求上下文实例中,如下所示:

context_instance = RequestContext(request, {
'recent_files': recent_files
})

然后像这样调用请求...

return render_to_response('index.html', context_instance = context_instance)

关于html - 图像不显示。 Django ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12097396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com