Reputation:
I am trying to connect js to html in django.
When i include script inside html file it excetutes the command, however i created seperate js file and linked to django so it does not work whereas I linked css file and it works fine ,
I am learning and using tutorials some of them are old and i do not know whether i am using old style and this is why linking js to django does not work. Would be happy if you could help to understand where i am doing wrong:
in index.html
<!DOCTYPE html>
{% load static %}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="{% static 'school/css/main.css' %}">
</head>
<body>
<div>{% block content %}{% endblock %} </div>
<script type="text/javascript" scr="{% static 'school/js/main.js' %}"> </script>
</body>
</html>
in settings
i have :
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]
and main.js
file:
alert ("Hello");
My django version is my django version is 2.2.6
Upvotes: 0
Views: 149
Reputation: 68
Depending on which version of Django you are using, {% load staticfiles %}
no longer exists. I think this has been removed with Django 2.
I just found this: {% load static %} and {% load staticfiles %}: which is preferred?
Upvotes: 1