DEV Community

Joumana
Joumana

Posted on

Adding JavaScript to a Django built website

Hello everyone,

I am trying to add some vanilla JavaScript to a website I built on Django. I added a js file in the static file. However, when I inspect the page the JavaScript does not appear. When I check the source, I see that my page has access to the javascript file.

I am really not sure what I am doing wrong. Any advice or help would be much appreciated.

Cheers,

Joumana

Top comments (5)

Collapse
 
ben profile image
Ben Halpern •

Hey Joumama, can you post the contents of the JS file and also the HTML page you want it to run in?

Collapse
 
joumanae profile image
Joumana •

Hi Ben,

Thank you for your help. One of the links is HTML & the other is JavaScript.

codeshare.io/amPMVw (HTML)

codeshare.io/anAnVv (JavaScript)

Best,

Joumana

Collapse
 
thepracticaldev profile image
dev.to staff •

Hmmm... I think this is the issue

<link href="{% static 'script/introduction.js' %}">
Enter fullscreen mode Exit fullscreen mode

Is this where you're trying to load that external JS file? I think it should look like this:

<script src="{% static 'script/introduction.js' %}"></script>
Enter fullscreen mode Exit fullscreen mode

The <link> tag is for external css and the <script> tag is for js. That may be your issue unless I'm missing something. That seems like an easy mistake to make.

Thread Thread
 
ben profile image
Ben Halpern •

Woops. Accidentally used the staff account... Logged in to both in separate windows. Gotta stop doing that 😳

Thread Thread
 
joumanae profile image
Joumana •

Hi Ben! Thanks for the feedback. I changed it to &amp; still not working. I think I will just try &amp; find a different way to make the timeline interactive. Thanks for your help. </p>