Downloading file from FileField in Django with a HTTP link in a HTML file
<p>I create a link that when a user press it, it will download a pdf file from the media folder in Django to the users machine.</p>

<p>I tried different methods but all were wrong for me. It tells me that the file can not be found, or the code is running but the file is corrupted.</p>

<p>My Html link:</p>

<pre><code>&lt;td&gt;  &lt;a href="/download/"&gt;Download&lt;/a&gt;&lt;/td&gt;
</code></pre>

<p>My url pattern links into a view:</p>

<pre><code>url(r'^download/$', views.DownloadPdf),
</code></pre>

<p>My FileField is like this: </p>

<pre><code>upload_pdf = models.FileField()
</code></pre>

<p>Following snippet code is the view that downloads a corrupted pdf:</p>

<pre><code>def DownloadPdf(request):

filename = '/home/USER/PycharmProjects/MyProject/media/Invoice_Template.pdf'
response = HttpResponse(content_type='application/pdf')
fileformat = "pdf"
response['Content-Disposition'] = 'attachment;
filename=thisismypdf'.format(fileformat)
return response
</code></pre>

<p>So, what I have to do to make it working ?</p>