-1

I am building a simple web app using Python's Flask library. I am able to successfully render HTML templates that are styled with CSS. When I try to link to a Javascript file, with the intent to use Jquery, I get a 404 error in the console. I have tried a number of different paths and moved the files around to try to resolve the issue. I link to a stylesheet from the same HTML file successfully, but I get an error even though I am following the same precedence when trying to link to the javascript file. When the HTML file is loaded the P tag is still there (Jquery file is written to remove it) and I get a "file not found error" when I inspect the page.

File structure

File structure in Sublime

Code in index.HTML

<body>
  <script
  src="https://code.jquery.com/jquery-3.6.0.min.js"
  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
  crossorigin="anonymous"></script>
  <script src="js/main.js"></script>
</body>

main.js code //Just hiding the

on load so I know it works

$("p").hide();

Error Message

Ty Swenson
  • 49
  • 8

2 Answers2

0

If you are using flask it should be like this:

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

you must download the jquery lib to your machine and then write this:

<script src={{url_for("static",filename="the_name_of_the_file_you_downloaded")}}></script>