Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有人能给我解释一下这个django视图部分吗_Python_Django - Fatal编程技术网

Python 有人能给我解释一下这个django视图部分吗

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

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”)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