-1

I have a chart.js file to show the candlestick graph that I took from tradingview. However, when I tried to load it to the pyhton file using flask, the chart.js somehow cant be loaded.

this is the python file

from flask import Flask, render_template
app = Flask(__name__,
            static_folder='./static',
            template_folder='./templates')



@app.route("/")
def index():
    title = "adsad"
    return render_template('index.html', title=title)

if __name__ == "__main__":
    app.run(debug=True)

this is the index.html code:

<html>  
    <head>
        <Title>Coinview</Title>
        <!-- load the lightweight library from tradingview -->
        <script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>
    </head>

    <body>
        <h2>Coinview</h2>
       

        <!-- load the chart from chart.js -->
        <div id='chart'></div>

        <div id="trades"></div>

        <h3>Settings</h3>
        <div id='settings'>
            <input type="checkbox" /> RSI            
            <input type='text' id='rsi_length' name='rsi_length' placeholder="14"/>
            Oversold
            <int type='text' id='rsi_oversold' name='rsi_oversold' placeholder="30"/>
            Overbought
            <input type='text' id='rsi_overbought' name='rsi_overbought' placeholder="70"/>

        </div>


        <!-- CONNECT TO BINANCE DATA STREAM -->
        <script>
        //var binanceSocket = new WebSocket('wss://stream.binance.com:9443/ws/bnbusdt@trade');
        console.log(binanceSocket)
        


        var tradeDiv = document.getElementById('trades')
        
        /*
        binanceSocket.onmessage = function (event) {
            console.log(event.data);

            var messageObject = JSON.parse(event.data)
            
            tradeDiv.append(messageObject.p)

        }
        */AbortController

        </script>
        <script src="chart.js"></script>
        <!-- "./static/chart.js" -->
        
        
    </body>



</html>

For the chart.js script, I just took directly from the trading view library (https://jsfiddle.net/TradingView/eaod9Lq8/).

I wonder where did I do wrong? I already created the static folder and put the chart.js in there, but seems to now working. I also already tried to change this part:

 </script>
        <script src="chart.js"></script>

to:

 </script>
    <script src="{{ url_for('static', filename='style.css') }}"></script>

but seems to not working also

1 Answers1

0

If you want to use a local file you should be referencing to the js file:

<script src="{{ url_for('static', filename='chart.js') }}"></script>

You may also want to try using a CDN instead of storing the file in your static folder:

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
f-starace
  • 278
  • 1
  • 17