如何解决Plotly url问题?

时间:2018-06-28 05:54:56

标签: django python-2.7 django-templates plotly

在通过python Plotly模块制作条形图时,为什么在Django中显示url问题。

Request URL:    http://127.0.0.1:8000/%3Cplotly.tools.PlotlyDisplay%20object%20at%200x00000000035B8DA0%3E.embed?width=200&height=200&link=false&showlegend=false

The current URL, <plotly.tools.PlotlyDisplay object at 0x00000000035B8DA0>.embed, didn't match any of these.

My views.py
import plotly as py
import plotly.graph_objs as go
def bar_chart(request):
    var = {}
    py.tools.set_credentials_file(username='myusername', api_key='*************')
    trace1 = go.Bar(
        x=['SAD', 'NEUTRAL', 'HAPPY'],
        y=[20, 14, 53],
        name='Dev'
    )
    data = [trace1]
    layout = go.Layout(barmode='stack')
    fig = go.Figure(data=data, layout=layout)
    plotly_url = py.plotly.iplot(fig, filename='chart_snippet.html',auto_open=True)
    pie_url = '''<iframe width="1200" height="1200" frameborder="0" seamless="seamless" scrolling="no" src=\"'''+str(plotly_url)+'''.embed?width=200&height=200&link=false&showlegend=false\"></iframe>'''
    var['pie_url'] = pie_url
    return render_to_response('home/graph_chart.html',var,context_instance = RequestContext(request))

我正在用Django模板制作条形图并进行渲染。那里我越来越错误。实际上,如果url不存在,则会出现此错误。但我没有称呼这个网址。通过plotly预定义的URL。

等待回应。任何帮助将不胜感激。

0 个答案:

没有答案