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
Other answers
Perfect solution to this problem is at http://stackoverflow.com/questions/446026/django-how-do-you-serve-media-stylesheets-and-link-to-them-within-templates
Srinivas N Jay
Related Q & A:
- How do I make a python web program that is on a ubuntu server allow access to the server?Best solution by Yahoo! Answers
- How can I make a dynamic web page in PHP?Best solution by Yahoo! Answers
- How do i make a my yahoo but not a home page?Best solution by Yahoo! Answers
- How do I make a Yahoo 360 page?Best solution by Yahoo! Answers
- How can I make a page my home page?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.