Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.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读取()图像文件并将其发送到HttpResponse_Python_Django_Image_Httpresponse - Fatal编程技术网

使用Python读取()图像文件并将其发送到HttpResponse

使用Python读取()图像文件并将其发送到HttpResponse,python,django,image,httpresponse,Python,Django,Image,Httpresponse,我试图将一个图像返回到HttpResponse(image_数据),但我得到一个包含奇怪符号的页面。 我可以从该路径使用PIL to.show()图像,但我希望在浏览器中显示图像,而不是在绘图或照片查看器应用程序中显示图像 image_data = open("media/hello.jpg", "rb").read() return HttpResponse(image_data, content_type="i

我试图将一个图像返回到HttpResponse(image_数据),但我得到一个包含奇怪符号的页面。 我可以从该路径使用PIL to.show()图像,但我希望在浏览器中显示图像,而不是在绘图或照片查看器应用程序中显示图像

        image_data = open("media/hello.jpg", "rb").read()
        return HttpResponse(image_data, content_type="image")
怪异符号:ÿØÿá�图像信息��二,*������������ÿì�小鸭�����D��ÿî�土坯�dÀ���ÿÛ�„�

利用

from django.http import FileResponse

def send_file(response):

    img = open('media/hello.jpg', 'rb')

    response = FileResponse(img)

    return response