[Answer]-Using django-compressor with render_block from sekizai_tags

1👍

It seems django-compressor explicitly provides this interaction, but not by putting render_block inside compress/endcompress:

{% load sekizai_tags %}
{% render_block "<js/css>" postprocessor "compressor.contrib.sekizai.compress" %}

In fact, the {% compress %} tag is simply not used here.

<head>
...
<!-- css -->
{% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %}
{% block css %}{% endblock %}
<!-- end js -->
...
</head>

... then in another template ...

{% block css %}
{% addtoblock "css" %}
    {{ form.media.css }}
    <link rel="stylesheet" type="text/css" href="..." />
{% endaddtoblock %}
{% endblock %}

I use block css just for the sake of having any block to put addtoblock in, otherwise it won’t work (unless it’s in the same template file):

If the {% addtoblock %} tag is used in an extending template, the tags must be placed within {% block %}...{% endblock %} tags.

Leave a comment