Skip to content Skip to sidebar Skip to footer

How To Download File From Django Admin

I created FileField in class Part in models.py. Also I get the link of this file by method file_link(self): origin = models.FileField(upload_to='origin_files', null=True, blank=Tru

Solution 1:

You have to configure MEDIA_URL in your django settings

https://docs.djangoproject.com/en/2.0/ref/settings/#media-url

Django builds your url the following way:

settings.MEDIA_URL + "origin_files/Presentation.pptx"

the MEDIA_URL default is an empty string, therefore you get the url "origin_files/Presentation.pptx" and your browser concatenates it to the current page, because the url doesn't start with a slash.

so you have to set the MEDIA_URL for example to '/media/'

then everything will work in your development environment.

On remote server this also requires configuring the web server appropriatelly for it to serve your MEDIA_ROOT to MEDIA_URL (out of the scope of this question obviously).

Post a Comment for "How To Download File From Django Admin"