[Answered ]-Django templates, including page(s) that injects code into parent block

2👍

Try to use django-sekizai for that purpose.

With sekizai, you can define a JavaScript block just before the </body>:

{% render_block "js" %}

And then whenever you need to add JavaScript to that block, you write this:

{% addtoblock "js" %}
    <script type="text/javascript">
        // your JavaScript
    </script>
{% endaddtoblock %}

If there are duplicates of the content in the {% addtoblock %} blocks, they will be used only once.

Leave a comment