0

This is the file structure of my website:

click here for image

for some reason, when I add the script to my index.html:

<script type="text/javascript" src="script.js"></script>

or

<script type="text/javascript" src="./script.js"></script>

it returns a 404 not found error. It must be something trivial I am missing here.

The error in chrome console looks like this

GET http://127.0.0.1:5000/script.js net::ERR_ABORTED 404 (NOT FOUND)

index.html and script.js as you can see are in the same folder, the strange part to me is when I double click on the file directly, it loads up fine:

file:///Users/.../matchik/templates/index.html loads fine

3
  • Please share the error message when asking to debug errors. p.s. your file structure image is not embedded correctly and cannot be viewed. Commented Nov 21, 2021 at 17:53
  • thanks @FinHARRIS I have added the error message Commented Nov 21, 2021 at 17:56
  • I found the answer that is most similar to my issue: stackoverflow.com/questions/46349370/… Commented Nov 22, 2021 at 16:36

1 Answer 1

0

Generally speaking, your HTTP server does not know about the script.js file. Whatever HTTP server you using you need to make sure it knows where the file is and has access to it. Refer to your HTTP server configuration. Or post more details on how you start the app.

[Upd] Oh, I see that you're loading your index.html directly with the browser simply by opening it: file:///Users/.../matchik/templates/index.html

Try to serve the contents of your app with the HTTP server. Running a simple local HTTP server

Otherwise, your browser won't be able to resolve your files requested by the HTML file you opened. That is partly because of the browser's security policies. Otherwise, any page could request any resource from the filesystem.

Have fun ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. I'm using PyCharm's internal webserver to start the webserver. When I load index.html directly with the browser, it surprisingly detects the js file while the webserver does not. Is there a configuration that needs to be done within PyCharm?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.