Why can't I get this to work

Resolved*
I found the error.
this: src={% static “js/jsScript.js” %}
should have been this:
src="{% static ‘js/jsScript1.js’ %}"
I even went back and removed all my ‘STATIC_ROOT’ and STATIC_DIR info in my settings.py and it still worked once I fixed this error.

######## Original question ##########

I’m just trying to get myself to understand how the javascript file links with the HTML and I can not get this to work…

the HTML code:

<!DOCTYPE html>
{% load static %}

<html>

<head>
  <meta charset="utf-8">
   <title> Testing JavaScript Files</title>
     <script type="text/JavaScript" src={% static "js/jsScript.js" %}> </script>

 </head>
<body>

<h1> It's running </h1>
<button id="clickme" onclick="doSomething"> click me </button>
</body>
</html>

The javascript file code:

// JavaScript file
//const body_tag = document.getElementsByTagName("BODY");
const clickbutton = document.getElementsById("clickme");

function doSomething(){

  alert("JavaScript file succcessfully linked");
}

window.onload = function(){
  document.getElementById("clickme").addEventListener("click", doSomething);
}

and the command prompt response after I runserver:
[15/Mar/2019 19:01:21] “GET /index/ HTTP/1.1” 200 297
[15/Mar/2019 19:01:21] “GET /static/js/jsScript.js HTTP/1.1” 404 1666

What am I not understanding? Help

1 Like