有人可以帮助我吗?我有FileField()
可以从管理面板上传.doc或.pdf文件。我可以像admin一样上传文件,但不能像user一样下载此文件。下载链接不起作用?
models.py
class Book(models.Model):
"""Model representing a book (but not a specific copy of a book)."""
title = models.CharField(max_length=200)
author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True)
summary = models.TextField(max_length=1000, help_text="Введите краткое содержание книги")
genre = models.ManyToManyField(Genre, help_text="Выберите жанр книги")
language = models.ForeignKey('Language', on_delete=models.SET_NULL, null=True)
specifications = models.FileField(upload_to='router_specifications')
book_detail.html
<p><strong>Download:</strong><a href="{{ book.specifications.url }}">Download</a></p>
答案 0 :(得分:0)
您是否定义了MEDIA_URL和MEDIA_ROOT设置变量并添加了用于提供媒体文件的视图? https://docs.djangoproject.com/en/2.1/howto/static-files/#serving-files-uploaded-by-a-user-during-development