Javascript code cannot be run

It is my first django project so i am sorry for any glaring issues.

I have a basic app which has a templates folder which contains an html file and a javascript file. When I cd to the project and paste python runserver and open it in my browser (Firefox), i get this warning and javascript does not print anything in the console.


Loading failed for the with source “”.

Here is the file structure (i didnt add the default files):


from django.urls import path
from . import views

urlpatterns = [
    path("", views.home, name="home"),
    path('index views.index')

from django.shortcuts import render, HttpResponse

# Create your views here.
def home(request):
    return render(request, 'index.html',)


<!DOCTYPE html>

<script src='../index.js'></script>

<button onclick="myFunction()">Click me!</button>



console.log('hello world');
function myFunction() {
    alert("Hello from a static file!");

Your JavaScript files aren’t templates, they belong in your staticfiles directory. Also, the url would (usually) be constructed with the static tag.

See the work you would have done at Writing your first Django app, part 6 | Django documentation | Django in the official Django tutorial, along with the docs referenced on that page.

If you haven’t worked your way through either the Official Django Tutorial or the Django Girls Tutorial, that really should be your starting point.

Thanks for that!
I have been following a youtube tutorial and was stuck as i couldn’t figure out why my files would not load. I have used the static tag but i omitted it here as i thought it wasnt the culprit. I added it back to get

<script src="{% static 'myapp/index.js' %}" ></script>

instead of

<script src="{% static '/index.js' %}" ></script>

…which solved my issue!