I am new in Django and I need some assist. I want to download the file which path is in plik.localisation (it has been taken from loop). The problem is with the path. Could someone help me what I am doing wrong? My view.py is:
def download(request, path):
file_path = os.path.join(settings.MEDIA_ROOT, path)
if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/pdf")
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
return response
raise Http404
Urls
path('download/<str:path>',views.download, serve, name="download"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Html where {{plik.localisation}} is a comes from for loop (plik.localisation in lacalisation)
<div class="com">
{{plik.localisation}} <a href="{% url 'download/path' %}" class="button">download</a>
</div>