My jquery function doesn't work with django

Can't run jquery with my django html page.

I tried to run with html and it's work. But with django nothing happens.

Here's my main_page.html :

{% load static %}
        <link rel="stylesheet" href="//">
        <link rel="stylesheet" href="//">
        <script src=""></script>
        <link rel="stylesheet" href="{% static 'js/blog.js' %}">
        <link rel="stylesheet" href="{% static 'css/blog.css' %}">

        <div class="form-group">
          <textarea class="text" style="display:inline" id="Textarea" ></textarea>
          <textarea class="text" style="display:inline" disabled="disabled" id="Textarea2"></textarea>


and my blog.js file under static/js/blog.js :


I expect for the Textarea2 to hide.

2 answers

  • answered 2019-07-21 14:11 Saurabh Pabhare

    1. Make sure your has STATIC_URL = '/static/'
    2. Set the STATIC_ROOT setting to the directory from which you’d like to serve these files STATIC_ROOT = "/var/www/"
    3. Run the collectstatic management command: python collectstatic

  • answered 2019-07-21 14:16 charlietfl

    <link> is not for javascript, you need a <script> tag


    <link rel="stylesheet" href="{% static 'js/blog.js' %}">


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