Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 显示数据库项的列表_Python_Django_Django Models_Django Views - Fatal编程技术网

Python 显示数据库项的列表

Python 显示数据库项的列表,python,django,django-models,django-views,Python,Django,Django Models,Django Views,我想显示数据库条目名称的列表。这些条目的类型为FileField() 我试图在我的html中显示它们,但什么也没有显示 型号.py class UploadedFile(models.Model): the_file = models.FileField() class Showing_File(ListView): model = UploadedFile template_name = 'index.html' context_object_name = '

我想显示数据库条目名称的列表。这些条目的类型为
FileField()

我试图在我的
html
中显示它们,但什么也没有显示

型号.py

class UploadedFile(models.Model):
    the_file = models.FileField()
class Showing_File(ListView):
    model = UploadedFile
    template_name = 'index.html'
    context_object_name = 'the_uploaded_files_list'
视图.py

class UploadedFile(models.Model):
    the_file = models.FileField()
class Showing_File(ListView):
    model = UploadedFile
    template_name = 'index.html'
    context_object_name = 'the_uploaded_files_list'
index.html

 {% for file in the_uploaded_files_list %}
<h1>  {{ file.the_file }} </h1>
{% endfor %}
{u上传的文件\u列表%中的文件%
{{file.the_file}
{%endfor%}

基本上,FileField是一种文件类型,因此您必须在最后添加.url才能在模板中显示文件

<h1>  {{ file.the_file.url }} </h1>
{{file.the_file.url}

您遇到了什么错误?您是否尝试过
{{file.the_file.name}
@EdwinCruz没有出现错误,我的
index.html
出现,但由于某种原因没有列表。数据库中有很多条目,所以我应该在加载时看到它们,但什么也没有出现。我上面的html代码也包含在主体中,因此应该是可见的。我尝试过
.name
,但它没有带来任何乐趣。在for循环结束时,将此
{%empty%}对象添加到模板中,但在其内部,并查看它是否显示h1