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
#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


Messages In This Thread
first django site-ms word/pdf files - by jon0852 - Oct-17-2017, 10:19 PM
RE: first django site-ms word/pdf files - by homayoon_hashemi - Nov-19-2017, 08:39 PM

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,467 Feb-11-2020, 02:59 AM
Last Post: menator01
  Django problem with files menator01 1 2,022 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,188 Aug-06-2019, 07:23 AM
Last Post: fishhook
  TypeError: missing 1 required positional argument (word counter Django app) Drone4four 2 14,738 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,450 Jun-30-2019, 12:21 AM
Last Post: scidam
  convert html to pdf in django site shahpy 4 6,137 Aug-17-2018, 11:10 AM
Last Post: Larz60+
  Django loading static files Dutchpy 7 24,175 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