Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

277
Views
JavaScript File is not working in template django

I am trying to connect the javascript page to the HTML template. I tried many ways but It doesn't show anything. There are no errors but Js file is not responding.

The index.html file is:


    {% extends "network/layout.html" %}
{% load static %}

{% block body %}
    <!-- <form action="" method="">
        
        <input type="text" name="post" id="post-body">
        <input type="submit" name="" id="postbtn" value="Post">
    </form> -->

    <input type="submit" name="btn" id="btn" value="check">
{% endblock %}

{% block script %}
    <script src="{% static 'network/post.js' %}" type="text/javascript"></script>
{% endblock %}

the post.js file is:


    document.addEventListener('DOMContentLoaded', function(){
    document.querySelector('#btn').onclick = function(){
        document.querySelector('#heading').innerHTML = 'hello';
    };
})

alert("Hello, Welcome to Javatpoint");  

the settings.py :


    # Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'

and urls.py file:


    from django.urls import path
from .views import *
from . import views



urlpatterns = [
    path("", views.index, name="index"),
    path("login", views.login_view, name="login"),
    path("logout", views.logout_view, name="logout"),
    path("register", views.register, name="register"),

    path('posts', compose_post, name='post' )
]

Please help me with this. I will be very thankful to you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just include this in your layout.html

{% block script %}
{% endblock script %}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!