djangodjango-templatespygal

How I can embed pygal charts in django templates


I use pyGal for making charts, but I can't insert them in django templates. It works great, if I try like this in views.py

 return HttpResponse(chart.render())

But when I make something like this in my template in doesn't work at all

 {{chart.render}}

Solution

  • The tutorial on pygal is accurate, however the issue you are probably seeing is from flask escaping html by default. In your template add:

    {{ graph|safe  }}
    

    or

    {{ graph.render()|safe  }}
    

    Depending what you pass to the template.

    This solved the issue for me.