Here are the lines to read file & download in django :
def download(request):
file_name =request.GET.get('file_name', '')
path_to_file = "C:\Users\CV_Uploads\uploadfiles\uploadfiles" + "\\" + file_name
fileanme = open('r'. path_to_file , "rb") # **ERROR HERE**
mimetype = mimetypes.guess_type('path_to_file')[0]
if not mimetype: mimetype = "application/octet-stream"
response = HttpResponse(fileanme.read(), mimetype=mimetype)
response["Content-Disposition"]= "attachment; filename=%s" % os.path.split(path_to_file)[1]
return response
Problem:
Was working fine with hardcoded values but now as i make this code dynamic by joining path_to_file with file_name
. It says: AttributeError at /download/ . . . .'str' object has no attribute 'path_to_file'
How to solve this attribute error?