I have several Django templates, some of which have different forms. Some forms use custom widgets that need their own JS and CSS resources. These resources are correctly specified in each form.media
The correct place I found to place all the media links is in the <head> , right above my own css file. This will allow me to override the appearance of custom widgets if I want. So there is something like in my templates:
{% block form_media %} {{ form1.media }} {{ form2.media }} {% endblock %}
(some templates have more than one shape)
Now, if both forms use the same widget, the same JS and CSS files will be referenced twice. It may not be good. Is there any reasonable way to combine all the links to the media?
It simply calls the special tag {% context_form_media %} , which will display media of all forms in the context of the request.
source share