I am trying to download a file when a link is clicked. The link is generated dynamically using javascript when the file has been created. In my template the function that adds the links looks like:
function Download(desiredLink) {
var a = $('<a />');
a.attr('download',desiredLink);
desiredLink = {{MEDIA_URL}} +desiredLink+'.docx';
a.attr('href',desiredLink);
a.text("Download");
$('body').append(a);
};
I have specified the MEDIA_URL in my settings.py file like:
MEDIA_ROOT = os.path.join(BASE_DIR, 'documents/')
MEDIA_URL = '/documents/'
The link generated has the correct url when I inspect it. But when I click the button it tries to download the file but says Failed-No file
. Any solution would be appreciated. The generated link looks like: localhost:8000/documents/test.docx
. And the files are found in the documents folder which is found in the root folder of the project.
Thanks in advance