我试图使用下面的行显示python脚本输出的图像,但不是在浏览器中显示,而是下载文件而不是显示代码
这是我在views.py中创建的函数:
def adc(请求): file=“C:\Users\TheBoss\Downloads\New\u test.xlsx” df=pd.read\u excel(文件、工作表\u name='Graph')
plt.plot(df['Date'], df['Video Device - Not Responding'], label = 'Video Device - Not Responding')
#plt.plot(df['Date'], df['30th Apr'], 'b', label = '30-Apr')
plt.xticks(rotation=45)
plt.tick_params(axis='x', which='major', labelsize=6)
# naming the y axis
plt.ylabel('Condition Count')
# giving a title to my graph
plt.title('Condition')
# function to show the plot
plt.legend()
#plt.show()
plt.savefig('C:\\Users\\TheBoss\\Downloads\\test.png')
image_data = open("C:\\Users\\TheBoss\\Downloads\\test.png", "rb").read()
return HttpResponse(image_data, content_type="test/png")
通常,这应该足以以内联方式显示图像
它应该在大多数浏览器中显示为图像,如果您想在HTML中插入图像,您可以使用一个简单的
我从经验中知道,这在Edge、Firefox和Opera中都有效。有时浏览器需要额外的说服力来内联显示图像,在这种情况下,将头
Content-Disposition
设置为inline
通常是有效的相关问题 更多 >
编程相关推荐