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

119
Views
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 answers
Answer question

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 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!