Django и Javascript ReferenceError: function is not defined at HTMLButtonElement.onclick

Итак, у меня есть index.js в static/network/index.js, и я хотел бы, чтобы функции, которые я там определяю, запускались в шаблонах Django. Файл связан и {% load static%}, но, к сожалению, когда я нажимаю кнопку с параметром onclick="justtest()", в консоли появляется ошибка "ReferenceError: function is not defined at HTMLButtonElement.onclick"

layout.html

{% load static %} // This is where static files should be loaded.


<!DOCTYPE html>
<html lang="en">
    <head>
        <title>{% block title %}Social Network{% endblock %}</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
        <link href="{% static 'network/styles.css' %}" rel="stylesheet">
        <script src="{% static 'network/index.js' %}"></script> // And this is where the static files should also be loaded.

    </head>
    <body>

        <nav class="navbar navbar-expand-lg navbar-light bg-light">
            <a class="navbar-brand" href="#">Network</a>
            
            <div>
              <ul class="navbar-nav mr-auto">
                {% if user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'profile' user.username %}"><strong>{{ user.username }}</strong></a>
                    </li>
                {% endif %}
                <li class="nav-item">
                  <a class="nav-link" href="{% url 'index' %}" >All Posts</a>
                </li>
                {% if user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'followers_view' %}">Following</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'logout' %}">Log Out</a>
                    </li>
                {% else %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'login' %}">Log In</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'register' %}">Register</a>
                    </li>
                {% endif %}
              </ul>
            </div>
          </nav>
        
        <div class="body">
            {% block body %}
            {% endblock %}
        </div>
    </body>
</html>

index.html

index.js

function editcurrent(postid) {
console.log(postid)
} // I was just starting to create this function and then I noticed an error.


function justtest() {
    console.log("working")
} // Here I checked if this error does not apply to the argument that this function has.
Вернуться на верх