# How to render graphs in Jinja template

**URL:** <https://community.plotly.com/t/how-to-render-graphs-in-jinja-template/35541>\
**Category:** 📊 Plotly Python\
**Created:** [February 27, 2020, 7:39am UTC](https://community.plotly.com/t/how-to-render-graphs-in-jinja-template/35541 "2020-02-27T07:39:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Troy](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Troy](https://community.plotly.com/u/Troy)\
**Post date:** [February 27, 2020, 7:39am UTC](https://community.plotly.com/t/how-to-render-graphs-in-jinja-template/35541/1 "2020-02-27T07:39:57Z")

</div>

I’m trying to create PDFs from HTML using WeasyPrint & Jinja2. I’d like to include in these PDFs visualization using Plotly, but I do not undertand how to get a simple plot to display in the Jinja template. I have tried:

```auto
from jinja2 import Template, Environment, FileSystemLoader
from plotly.offline import plot
from plotly.graph_objs import Scatter

fig = plot([Scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])], output_type='div')

env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('FirstAttempt.html')
template_vars = {"title":"My Title","Plot":fig}

html_out = template.render(template_vars)

from weasyprint import HTML
HTML(string=html_out).write_pdf('Test.pdf')

```

HTML Template is:

```auto
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>{{ title }}</title>
</head>
<body>
    <h2>{{ title }}</h2>
    <div>
        {{ Plot }}
    </div>
</body>
</html>

```

Note that this works just fine for me if I pass a pandas df as the value of “Plot” using df.to\_html(). I was hoping using the same approach would work with plotly visualization, but it apparently doesn’t. Would appreciate the help as I am the newbiest of newbs…

Thanks!

---

<div class="post-metadata">

**Author:** ![UdayGuntupalli](https://avatars.discourse-cdn.com/v4/letter/u/a9adbd/32.png) [@UdayGuntupalli](https://community.plotly.com/u/UdayGuntupalli)\
**Post date:** [December 17, 2021, 4:48am UTC](https://community.plotly.com/t/how-to-render-graphs-in-jinja-template/35541/2 "2021-12-17T04:48:26Z")

</div>

Did anyone find a way to do it ?
