[Answer]-Best practice to use 'ad hoc' javascript in django?

1👍

The way I did this in my Django sites was to include an empty `

 {% block extrascripts %}
 {% endblock %}

in the head tag of base.html, then use that block for any template that needed to include extra JS:

 {% block extrascripts %}
 <script type="text/javascript" src="jquery-ultimate-super-plugin.js" />
 <script type="text/javascript">$.ultimateSuperPlugin(...)</script>
 {% endblock %}

Worked like a charm. You can even include {{ block.super }} in your block if you have multiple levels of template inheritance.

Leave a comment