I'm currently working on a template tag that renders forms nicely.
@register.inclusion_tag('myforms.html', takes_context=True)
def myform(context, form)
context['form'] = form
context['error_classes'] = 'has-error has-feedback'
return context
In myforms.html, I use some JavaScript libraries and css files. In the template I added the scripts:
<link rel="stylesheet" href="{% static 'xyz.css' %}"/>
<script lang="javascript" src="{% static 'xyz.js' %}"></script>
<div>
...
</div>
When rendering multiple forms on a singe site, those <links> and <script> are multiple times in the html document.
One possibility is to include them in the base template inside the <head> tag. But then they are in the html file even when they aren't needed.
Adding a {{ block head }} to the base template inside the <head> doesn't work either. For this {{ block.super }} is needed to append new js and css files, but {{ block.super }} doesn't work in includes (see https://stackoverflow.com/a/6566463/2014080).