0

I am trying to run a function from my javascript code, I have called linked the js function in my file

This is my structure:

project
   static
      css
        /main.css
      js
        /script.js
   templates
        /layout.html

This is what I have tried, placing it in my head tags

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

If I try filename ='js/script.js' - and specific the folder, neither works

My error in the js console is:

Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://127.0.0.1:5000/js/script.js

Thanks for any suggestions!

Dennis
  • 29
  • 2
  • 6
  • Try src="static/js/script.js" @Dennis does this work ? – BPDESILVA Jul 06 '19 at 16:32
  • @MRDR I have just tried, but unfortunately that did not work either and the same error appears. I am using Flask. – Dennis Jul 06 '19 at 16:36
  • try to look for similar answers here it will help - https://stackoverflow.com/questions/14711552/external-javascript-file-is-not-getting-added-when-running-on-flask – Akhilesh Jul 06 '19 at 16:59

1 Answers1

2
{{ url_for('static', filename='js/script.js') }}
Soufiane Hassou
  • 17,257
  • 2
  • 39
  • 75