我使用Django压缩器来存储静态资源。然而,当尝试压缩内联样式标记时,它会从样式标记中删除我需要用于其他内容的自定义属性
代码:
{% compress css inline %}
<style some-custom-attribute type="text/css">
*{
padding:0px;
margin:0px;
}
</style>
{% endcompress css %}输出
<style type="text/css">*{padding:0px;margin:0px}</style>预期结果
<style some-custom-attribute type="text/css">*{padding:0px;margin:0px}</style>发布于 2017-08-11 03:15:57
该解决方案在https://github.com/django-compressor/django-compressor/issues/690中有部分解释
在你的一个应用中(确保它在你的INSTALLED_APPS设置中高于compressor ),在模板文件夹compressor/css_inline.html中创建一个文件来覆盖它。
在该模板中,您可以将内容设置为如下内容
<style type="text/css"{% if compressed.media %} media="{{ compressed.media }}"{% endif %} some-custom-attribute>{{ compressed.content|safe }}</style>请注意,这个解决方案是相当黑客的,并将影响所有压缩的内联css输出。您可以通过编写自定义上下文处理器来使其更具动态性。
https://stackoverflow.com/questions/38978820
复制相似问题