Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
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 Respostas
Responde à pergunta

0

Just include this in your layout.html

{% block script %}
{% endblock script %}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda