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

121
Vistas
Execute javascript code present inside child template after the main template is rendered

I've a base template which serves as a common structure for child templates. Inside this base template, I've the jQuery library included right before the closing body tag.

base template

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    .
    .
</head>
<body>
{% block content %}

{% endblock %}
<script src="path/to/jQuery/library"></script>
</body>
</html>

Now my child template has the following code

child template

{% extends 'base_template.html' %}
{% block content %}
<h1>How you doing?</h1>

<script type="text/javascript">
   // this code is specific to this template, may not be used in another template
  // but can't use jQuery here since the library hasn't loaded yet
</script>
{% endblock %}

So how would I go about running javascript code inside child template only after the base template has finished loading the jQuery library?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to use 2 blocks:

base
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    .
    .
</head>
<body>
{% block content %}

{% endblock %}
<script src="path/to/jQuery/library"></script>
{% block scripts %}

{% endblock %}
</body>
</html>
child_template
{% extends 'base_template.html' %}
{% block content %}
<h1>How you doing?</h1>
{% endblock %}

{% block scripts %}
<script type="text/javascript">
    // this code can "use" jquery
</script>
{% endblock %}
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