I have a File model that stores the path to the path file in the file system. All files are stored in MEDIA_ROOT / files
In the template, I want to create a download link for the File object. What is the best way to do this? Should I use static file handling in django?
TIA!
UPD
File model
class File(models.Model): item = models.ForeignKey(Item) file = models.FileField(upload_to = os.path.join(MEDIA_ROOT,'items')) format = models.CharField(max_length = 255)
In the View element, I do the following:
files = File.objects.filter(item_id = id)
and pass files to the template
in the template, I use files.1.file.url , for example, and still have a bad url, for example site.com/home/dizpers/...
UPD2
Question related to us
Decision
My problem was in the file model, in the File field. In the upload_to parameter, I use the absolute path, but should use the relative path:
file = models.FileField(upload_to = 'items')
source share