【发布时间】:2023-12-14 03:31:01
【问题描述】:
我正在尝试使用以下行显示 python 脚本输出的图像,但不是在浏览器中显示,而是下载文件而不是显示的代码
这是我在views.py中创建的函数:
def adc(请求): 文件 = "C:\Users\TheBoss\Downloads\New_test.xlsx" df = pd.read_excel(file, sheet_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")
【问题讨论】:
-
感谢您的回复.....我试过但仍然下载而不是显示......
标签: python django httpresponse