Matplotlib into a Django Template

后端 未结 5 2056
时光取名叫无心
时光取名叫无心 2021-01-02 03:17

Im using python 3.4 and Django 1.8. I want to \"print\" a matplotlib result in a Django template. I reach this a few days ago, so I continue in other things of my Django App

5条回答
  •  隐瞒了意图╮
    2021-01-02 03:42

    Edit:

    try with

    graphic = cStringIO.StringIO()
    canvas.print_png(graphic)
    return render(request, 'graphic.html',{'graphic':graphic})
    

    You have to specify that your image is a binary string:

    
    

    Or actually save it to the filesystem and provide the path.

    Alternatively you could use Bokeh which can give you the html + javascript to embed the plot directly in the template, then it is dynamically generated and brings nice features.

提交回复
热议问题