使用Python读取()图像文件并将其发送到HttpResponse
我试图将一个图像返回到HttpResponse(image_数据),但我得到一个包含奇怪符号的页面。 我可以从该路径使用PIL to.show()图像,但我希望在浏览器中显示图像,而不是在绘图或照片查看器应用程序中显示图像使用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
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