CORS errors in Tradingview integration in Django Python

136 Views Asked by At

I have configured TradingView in Django Python and I am getting CORS errors in console and chart not loading, Already configured CORS for python, and rest external scripts working fine,

In settings.py...


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
]
MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    "django.middleware.common.CommonMiddleware",
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

]

CORS_ALLOWED_ORIGINS = [
    "http://127.0.0.1:8000",
]

below are configuration scripts added in HTML,


        <script type="text/javascript" src="https://charting-library.tradingview-widget.com/charting_library/charting_library.standalone.js"></script>
        <script type="text/javascript" src="https://charting-library.tradingview-widget.com/datafeeds/udf/dist/bundle.js"></script>

        <script>
        function initOnReady() {
            var widget = window.tvWidget = new TradingView.widget({
              library_path: "https://charting-library.tradingview-widget.com/charting_library/",
              debug: true, // uncomment this line to see Library errors and warnings in the console
              fullscreen: true,
              symbol: 'AAPL',
              interval: '1D',
              container: "tv_chart_container",
              datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com"),
              locale: "en",
              disabled_features: [],
              enabled_features: [],
            });
          };
          
          window.addEventListener('DOMContentLoaded', initOnReady, false);

        </script>

errors shown in the console are...

Access to script at 'https://charting-library.tradingview-widget.com/charting_library/bundles/runtime.22cd9f6fe908159906ae.js' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
blob:http://127.0.0.1:8000/283852f3-3565-423f-aeb4-75fc0a81c15e:2 
        
        
        GET https://charting-library.tradingview-widget.com/charting_library/bundles/runtime.22cd9f6fe908159906ae.js net::ERR_FAILED 200 (OK)
blob:http://127.0.0.1:8000/283852f3-3565-423f-aeb4-75fc0a81c15e:7  Access to script at 'https://charting-library.tradingview-widget.com/charting_library/bundles/en.3732.1bd67796122e14c1a819.js' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
blob:http://127.0.0.1:8000/283852f3-3565-423f-aeb4-75fc0a81c15e:3 
        
        
        GET https://charting-library.tradingview-widget.com/charting_library/bundles/en.3732.1bd67796122e14c1a819.js net::ERR_FAILED 200 (OK)
blob:http://127.0.0.1:8000/283852f3-3565-423f-aeb4-75fc0a81c15e:7  Access to script at 'https://charting-library.tradingview-widget.com/charting_library/bundles/9401.1a253c12a3b43291d008.js' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
blob:http://127.0.0.1:8000/283852f3-3565-423f-aeb4-75fc0a81c15e:4 
        
        
        GET https://charting-library.tradingview-widget.com/charting_library/bundles/9401.1a253c12a3b43291d008.js net::ERR_FAILED 200 (OK)
blob:http://127.0.0.1:8000/283852f3-3565-423f-aeb4-75fc0a81c15e:1  Access to script at 'https://charting-library.tradingview-widget.com/charting_library/bundles/library.922da4a8fbaf39eb2333.js' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
blob:http://127.0.0.1:8000/283852f3-3565-423f-aeb4-75fc0a81c15e:5 
        
        
        GET https://charting-library.tradingview-widget.com/charting_library/bundles/library.922da4a8fbaf39eb2333.js net::ERR_FAILED 200 (OK)
0

There are 0 best solutions below