无法在django中将绘图显示为模板

问题描述 投票:2回答:1

我试图在我的django模板上绘制一个可绘制的图,但是无法这样做,得到一个空白模板。

views.py

#plotly libraries used
import plotly.graph_objects as go
import plotly.express as px
import plotly.offline as py

def home(request):
    df=index(request) #returns a dataframe
    #overall cases
    total_df = df.groupby(['Country'])['Total Cases'].sum()
    total_df = total_df.reset_index()
    fig0 = px.scatter_geo(total_df,locations="Country", locationmode='country names', 
                          color="Total Cases", size='Total Cases',hover_name="Country",
                          projection="orthographic",color_continuous_scale=px.colors.sequential.deep,
                          )
    fig0 = go.Figure(data=fig0)
    plot_div0 = py.plot(fig0, include_plotlyjs=False, output_type='div',config={'displayModeBar': False})

    return render(request, 'test/welcome.html', {'plot_div0':plot_div0})

welcome.html

{{ plot_div0 | safe }}
python django plotly
1个回答
0
投票
welcome.html

<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

© www.soinside.com 2019 - 2024. All rights reserved.