url_for not working for Javascript file in HTML

Hopefully, I’m missing something simple here but when I run the following HTML code through Flask the Javascript file fails to run. When I put my Javascript code from my file inline: alert('boo'), it works fine, so my Javascript code isn’t the issue. The javascript file is indeed in my static folder and the names match, also the issue is the same on multiple browsers.

No error is shown and the HTML page loads normally as though there is no Javascript/it is ignoring it.

EDIT – There is an error, I was only looking in terminal. In the browser console it says Uncaught SyntaxError: Unexpected identifier and highlights my src.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
    <script> type="text/javascript" src="{{url_for('static', filename='javascripts.js')}}"></script>
</head>
<body>
    <h1>Hello World</h1>
</body>
</html>

47 thoughts on “url_for not working for Javascript file in HTML”

  1. Pingback: is keto a fad diet
  2. Do you mind if I quote a few of your posts as long as I
    provide credit and sources back to your blog?
    My website is in the very same niche as yours and my visitors would really benefit from a
    lot of the information you present here. Please let me know
    if this ok with you. Regards!

    Reply
  3. I just like the valuable info you supply to your articles.

    I will bookmark your blog and check again right here regularly.
    I’m rather certain I will be told many new stuff right here!
    Best of luck for the following!

    Reply
  4. Howdy! I could have sworn I’ve visited this website before but after browsing through
    many of the articles I realized it’s new to me. Regardless, I’m
    certainly delighted I found it and I’ll be book-marking it and
    checking back often!

    Reply

Leave a Comment