1

I am trying to use jQuery with my django app but when I use the inspector and look at the .js file in Sources, I am seeing this error. I know this question has come up before, but I haven't been able to figure out how to fix it in my case. This is the HTML for the page I am trying to load:

{% extends 'great_songs_app/base.html' %}
{% load static %}


{% block content %}
<script src="{% static 'great_songs_app/playlist_jquery.js' %}"> 
</script>
--code--
{% endblock %

And this is my base HTML file:

{% load static %}
<html lang="en-US">
  <head>
  	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link href="https://rsms.me/inter/inter-ui.css" rel="preload" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="{% static 'great_songs_app/style.css' %}">
  	<title>Great Songs</title>
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <a class="navbar-brand" href="{% url 'great_songs:great_songs' %}">Great Songs</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbar">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a class="nav-link" href="{% url 'great_songs:great_songs' %}">Songs</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'great_songs:artists' %}">Artists</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'great_songs:genres' %}">Genres</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'great_songs:producers' %}">Producers</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'great_songs:labels' %}">Labels</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'great_songs:playlists' %}">Playlists</a>
          </li>
        </ul> 
        <ul class="navbar-nav" id="login-list">  
          {% if user.is_authenticated %}
            <li class="nav-item login">  
              <a class="nav-link" href="{% url 'users:logout' %}" id=login>log out</a>
            </li>  
          {% else %}
            <li class="nav-item login">  
              <a class="nav-link" href="{% url 'users:login' %}" id=login>log in</a>
            </li>
            <li class="nav-item login">  
              <a class="nav-link" href="{% url 'users:register' %}">register</a>
            </li>
          {% endif %}
        </ul>
      </div>
    </nav>

    <div class="container">
    {% block content %}
    {% endblock %}
    </div>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>

This is my jQuery file:

jQuery(document).ready(function($) {
    $(".playlist-row").click(function() {
        window.location = $(this).data("href");
    });
});
7
  • 1
    jquery script included properly? Commented Feb 1, 2019 at 1:31
  • you mean including my .js file? Commented Feb 1, 2019 at 1:37
  • 1
    the jquery script itself Commented Feb 1, 2019 at 1:37
  • edited my question to include js file Commented Feb 1, 2019 at 1:40
  • jQuery needs to be loaded in the document before your script tries to use it. Try moving your content block below the <script> tags Commented Feb 1, 2019 at 1:46

1 Answer 1

1

I had a similar problem and just I pasted the js files inside head tag.

Here is my base.html enter image description here Then inside body tag, the {% block content %}{% endblock %}.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.