小编Ans*_*rty的帖子

如何在 django 模板中显示已保存的动态创建的图像?

我在视图中创建了一个图并将该图保存为模板文件夹中的 png。但是当我尝试使用<img>模板 html 文件中的标签显示此保存的图像时,该图像不会显示。这是我的文件夹结构的图像: 文件夹结构

这就是我在视图中保存我的情节的方式:

def result(request):
    if request.POST and request.FILES:
        mycsv=pd.read_csv(request.FILES['csv_file'])
        c=mycsv.X
        #We divide by the class height(basically) so that Xi+1-Xi=1
        x = [d / 5 for d in c]
        n=len(x)
        b=mycsv.Y
        divi=np.sum(b)
        f = [e / divi for e in b] 
        #Thus sum(f)=1, makes calculation of mean simpler

        #PLOTTING BEGINS
        fig = plt.figure()
        ax = plt.subplot(111)
        ax.plot(x, f)
        plt.title('Pearson Type 1 ')
        ax.legend()
        #plt.show()
        fig.savefig('polls/templates/polls/plot.png')
        context = {'n':n,}
        return render(request, 'polls/result.html', context)
    else:
        return HttpResponse("Form …
Run Code Online (Sandbox Code Playgroud)

html python django image matplotlib

2
推荐指数
1
解决办法
2360
查看次数

标签 统计

django ×1

html ×1

image ×1

matplotlib ×1

python ×1