【发布时间】:2020-12-20 20:27:48
【问题描述】:
当我尝试在 django 模板中显示文件下载链接时遇到问题
消息:
AttributeError: 'NoneType' object has no attribute 'split'
File "c:\users\ramin\appdata\local\programs\python\python36-32\Lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
----------------------------------------
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
models.py:
from django.db import models
class Book(models.Model):
Title = models.CharField(max_length=100)
Writer = models.CharField(max_length=100)
Description = models.TextField()
Image = models.ImageField(default='default.jpg')
File = models.FileField(upload_to='PDF/')
def __str__(self):
return self.Title
views.py:
from django.views.generic.list import ListView
from . import models
class BookListView(ListView):
queryset = models.Book.objects.all()
template_name = 'Book/BookList.html'
模板:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Books List</title>
</head>
<body>
{% for x in object_list %}
<h2><a href="">{{ x.Title }}</a></h2>
<img style="width:100px" src="{{ x.Image.url }}">
<p><a href="{{ x.File.url }}" download="{{ x.Title }}">Download</p>
{% endfor %}
</body>
</html>
当我点击下载链接时,我可以成功下载文件,但我看到了这条消息
【问题讨论】:
-
simple_server.py
标签: python django django-models django-views django-templates