Python Forum
first django site-ms word/pdf files
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
first django site-ms word/pdf files
#1
I am developing my first website and would like a couple word documents and/or pdf's to be made available for download on the site. I'm assuming these are just considered static files, right? So, should those documents just go inside of the static files folder? Any guidance on how that may work would be appreciated!
Reply
#2
def download_course(request, id):
course = Courses.objects.get(pk = id)
path_to_file = get_path_to_course_download(course)

response = HttpResponse(mimetype='application/force-download')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = smart_str(path_to_file)
return response

Where get_path_to_course_download returns the location of the download in the file system (ex: /path/to/where/handle_uploaded_files/saves/files/the_file.doc)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python can't import Django and it's in the site-packages directory karkas 3 8,156 Feb-11-2020, 02:59 AM
Last Post: menator01
  Django problem with files menator01 1 1,948 Jan-05-2020, 04:20 PM
Last Post: menator01
  How do I extract specific lines from HTML files before and after a word? glittergirl 1 5,097 Aug-06-2019, 07:23 AM
Last Post: fishhook
  TypeError: missing 1 required positional argument (word counter Django app) Drone4four 2 14,608 Jul-11-2019, 09:34 PM
Last Post: Drone4four
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,309 Jun-30-2019, 12:21 AM
Last Post: scidam
  convert html to pdf in django site shahpy 4 6,034 Aug-17-2018, 11:10 AM
Last Post: Larz60+
  Django loading static files Dutchpy 7 23,941 Oct-13-2017, 10:25 AM
Last Post: hbknjr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020