I need to provide a button, once the user click on it It will download a PDF file or Image.
I have been tried so many ways out there. non of them works. and I couldn't find any tutorial for this topic.
I need to provide a button, once the user click on it It will download a PDF file or Image.
I have been tried so many ways out there. non of them works. and I couldn't find any tutorial for this topic.
I'll copypaste a working code from my own question (Django 1.7, Python 3.4): Django 1.7: serve a pdf -file (UnicodeDecodeError)
from views.py:
from django.http import HttpResponse
def download(request, file_name):
file = open('path/to/file/{}'.format(file_name), 'rb')
response = HttpResponse(file, content_type='application/pdf')
response['Content-Disposition'] = "attachment; filename={}".format(file_name)
return response