Python 有人能给我解释一下这个django视图部分吗
def下载(请求,路径):Python 有人能给我解释一下这个django视图部分吗,python,django,Python,Django,def下载(请求,路径): 我看了一篇关于如何上传img的文章,代码很好,但我不理解这部分://问题是:什么是hr?其他部分应该很清楚。解释一下:(file_path=os.path.join(settings.MEDIA_ROOT,path)如果os.path.exists(file_path,'rb'):打开(file_path,'rb')作为file:response=hr(file.read(),content_type=“application/admin_upload”)respo
我看了一篇关于如何上传img的文章,代码很好,但我不理解这部分://问题是:什么是
hr
?其他部分应该很清楚。解释一下:(file_path=os.path.join(settings.MEDIA_ROOT,path)如果os.path.exists(file_path,'rb'):打开(file_path,'rb')作为file:response=hr(file.read(),content_type=“application/admin_upload”)response['content-Disposition']=“inline;filename=”+os.path.basename(file_path)返回响应(Http404)在我看来,的文档非常清楚。您对此函数有什么问题?response=hr(file.read(),content_type=“application/admin\u upload”)response['content-Disposition']='inline;filename='+os.path.basename(file_path)我理解它发送httpresponse,但不理解其他的
file_path = os.path.join(settings.MEDIA_ROOT , path)
if os.path.exists(file_path):
with open(file_path , 'rb') as file:
response = hr(file.read(),content_type="application/admin_upload")
response['Content-Disposition'] = 'inline;filename='+os.path.basename(file_path)
return response
raise Http404