Flask Application - How to link a javascript file to website Flask Application - How to link a javascript file to website flask flask

Flask Application - How to link a javascript file to website


Ah yes, luckily I am currently developing a flask application at the moment.

You are currently missing the static folder which by default flask looks into, a folder structure something like this:

|FlaskApp----|FlaskApp--------|templates        - html files are here--------|static        - css and javascript files are here

Two important default folders that Flask will look into templates and static.Once you got that sorted you use this to link up with your javascript files from your html page:

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

Hope that helps any questions just ask.

Plus - A good article to read but not super related but it talks about the folder structure of flask is this: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps


So your index.html is at app/templates/index.html, and your jQuery is at app/javascript/jQuery.js right?

I think your path is wrong. Try this:

<script src="../javascript/jquery.js"></script>


Try using src="app/javascript/jquery.js".

Also, I noticed you include jquery.js twice - on line 7 and 28.