Python Forum

Full Version: first django site-ms word/pdf files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
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)