Django template template requires js / css

We created a template tag that adds a button that opens a dialog box (to display additional information).

The dialog needs an additional js file and one css file.

At the moment, both the js and css file are added as a global requirement in our Django application. But since dialogue is only needed for some special Django views, we would like to remove the js / css file from global requirements.

But we cannot automatically add files if the view contains a template tag. There is nothing like Media classes for Django forms. (see https://docs.djangoproject.com/en/1.8/topics/forms/media/ )

With accept_context = True, you can read the context in the template tags, but we cannot add files, because the context is just a pass along the value of the original Django context.

Any ideas on how to add js / css files only in the html header if , does the template tag exist in the template?

+4
source share

Source: https://habr.com/ru/post/1615237/


All Articles