1

I'm trying to get graphs onto my flask website using Chart.js. When I use the CDN link below everything functions perfectly; this should mean my code is fine.

  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js" integrity="sha512-d9xgZrVZpmmQlfonhQUvTR7lMPtO7NkZMkA0ABN3PHCbKA5nqylQ/yWlFAyY6hYgdF1Qh6nYiuADWwKB4C2WSw=="crossorigin="anonymous"></script>

But when I try to access Chart.js in node_module, nothing works. The line below is what I'm using

<script src="{{ url_for('static', filename='node_modules/chartjs/dist/Chart.js') }}"></script>

This is my first time using npm, so I'm assuming I messed up somehow. I've installed npm, ran npm init in static. After running, it looks like this. I then ran npm install chart.js --save, it installed fine. Based off this answer, and this line <script src="path/to/chartjs/dist/Chart.js"></script> from Chart.js, I should be fine.

What gives? Where can I start looking to figure the problem. I've seen other

The Candy King
  • 89
  • 1
  • 1
  • 10

1 Answers1

0

What gives? Where can I start looking to figure the problem.

The place to start looking is the rendered value for the script src attribute once it makes it to the browser. Not the uninterpolated expression that you have shared with us. If in fact you are interpolating the values of your expression. If it does not match the relative or absolute path that does work when you enter it manually then you have to look at how the expression is being interpolated and adjust your input from there.

The expression itself is not a valid src path.