0

I am new to web programming and I have the following issue.

So I am trying to set up a small server on Jupyter notebook. The issue right now is when I do

<script src="../src/main.js">

in my HTML, it cannot find the corresponding JS file. I tried http://localhost:8888/src/main.js as the path but this does not work either as it is forbidden.

I am wondering is there any way to work around this?

Thanks

EDIT: the project structure is similar to the following

/
  server.py
src/  
  main.js  
templates/  
  main.html

server.py is a flask application that can render the main.html.

4
  • can you please add your project structure Commented Apr 2, 2020 at 3:50
  • I just updated the question, thanks! Commented Apr 2, 2020 at 14:15
  • can you share the error stack or code you trying to execute because I could not able to replicate the issue in my system Commented Apr 2, 2020 at 15:18
  • It is GET http://localhost:8888/src/main.js net::ERR_ABORTED 404 (Not Found) or simply 404 not found if I do ../src/main.js Commented Apr 2, 2020 at 16:23

1 Answer 1

1

to include the static files in the flask first you need to follow the folder structure

I have attached the link below for your reference Here

and answering your question

move the js file to a static/ subdirectory

url_for('static', filename='path/to/file')

in your HTML file

you can find more details here

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

1 Comment

Thanks a lot, it worked! It's really hard to navigate through the Flask doc. from scratch...

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.