How can I make a download page?

How do I make a download button in my web page work with Django?

  • So if  people click on that download button, the file xyz.pdf on server should be  downloaded. Framework: Django Language: Python OS: Ubuntu  For example, let us assume that I have a file "xyz.pdf" at  "/home/username/project/". I have a webpage with download button. So if  people click on that download button, the file xyz.pdf should be  downloaded.  What I have done, Created a webpage with download button with href as  "download/" (as you all know this url does not matter much) it is redirected to http://urls.py and finds the appropriate view say for example "xyzdownload" at xyzdownload I have following code, response = urllib2.urlopen('./project/xyz.pdf')     html = response.read() The error I am getting is unknown url type: ./project/xyz.pdf  Please let me know if you guys need more clarification. Thanks a lot

  • Answer:

    has a very good point, you should consider routing the request using static content rules in your http://urls.py file, see example[1]. What you are trying to do with urllib2.urlopen is essentially make an HTTP request, to your own filesystem, without a specified protocol - this is raising a URLError as described in the python documentation for urllib2[2]. If you're deadset on manually handling the request for the pdf, I suggest that you use open()[3] - you should be able to find documentation & additional examples online. If you can't, a better place for your question would be http://stackoverflow.com. 1. https://gist.github.com/79a04cfa8c37136baa00 2. http://docs.python.org/library/functions.html#open 3. http://docs.python.org/library/urllib2.html#urllib2.URLError

Auston Bunsen at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.