График Plotly не отображается в веб-приложении django

Я пытаюсь сделать это уже несколько часов и все еще не могу понять.

Это мой код для графика в 'functions.py'

def candles():
    symbol = 'AAPL'
    stock = yfinance.Ticker(symbol)
    hist = stock.history(period='1y', interval='1d')
    figure = go.Figure(data = [go.Candlestick(x =hist.index,
                                             open = hist['Open'],
                                             high = hist['High'],
                                             low = hist['Low'],
                                             close = hist['Close'])])

    x_axis = figure.update_xaxes(
        title_text = 'Date',
        rangeslider_visible = True,
        rangeselector = dict(
            buttons = list([
                dict(count = 1, label = '1M', step = 'month', stepmode = 'backward'),
                dict(count = 6, label = '6M', step = 'month', stepmode = 'backward'),
                dict(count = 1, label = 'YTD', step = 'year', stepmode = 'todate'),
                dict(count = 1, label = '1Y', step = 'year', stepmode = 'backward'),
                dict(step = 'all')])))

    layout = figure.update_layout(
            title = {
                'text': 'AAPL',
                'y':0.9,
                'x':0.5,
                'xanchor': 'center',
                'yanchor': 'top'})

    y_axis = figure.update_yaxes(
            title_text = 'AAPL Close Price',
            tickprefix = '$')

    chart = plot(figure, x_axis, layout, y_axis, output_type = 'div')
    return chart

Мой 'views.py'

def chartView(request):

    candlestick = candles()

    context={

        'candlestick' : candlestick
    }
    return render(request, 'portfolio.html', context)

В portfolio.html я использую {{candlestick | safe}}

Вернуться на верх