Hello
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 manage.py runserver and open it in my browser (Firefox), i get this warning and javascript does not print anything in the console.
Error:
Loading failed for the with source “http://127.0.0.1:8000/index.js”.
Here is the file structure (i didnt add the default files):
project
app
templates
index.html
index.js
urls.py
views.py
urls.py
from django.urls import path
from . import views
urlpatterns = [
path("", views.home, name="home"),
path('index views.index')
]
views.py
from django.shortcuts import render, HttpResponse
# Create your views here.
def home(request):
return render(request, 'index.html',)
index.html
<!DOCTYPE html>
<html>
<script src='../index.js'></script>
<body>
<button onclick="myFunction()">Click me!</button>
</body>
</html>
index.js
console.log('hello world');
function myFunction() {
alert("Hello from a static file!");
}