Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

279
Vistas
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 Respuestas
Responde la pregunta

0

Just include this in your layout.html

{% block script %}
{% endblock script %}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda