to serve a downloadable link to a file(pdf or word doc) in django

In the application the user has the option of downloading the paper that is stored in the media folder within the app's directory. Now how do I get the option of downloading that paper working. The present code that I've provided below takes me to the URL from the current html page -

http://127.0.0.1:8000/authorViewSubmission/papers/some.pdf

The actual file is stored in media/papers/some.pdf

Can someone tell me how do i get the download link working here?

in settings.py

MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'

in my template

<td><a href ="{{ MEDIA_URL}}{{i.paper.url}}" class="btn btn btn-success" role="button">Download Paper</a></td>

Upvotes: 2

Views: 1016

Answers (1)

Lorenzo Pe&#241;a
Lorenzo Pe&#241;a

Reputation: 2263

To have a proper answer: {{ i.paper.url }} should be enough to get the full url.

Upvotes: 2

Related Questions