Django-compressor and template tags in Django

孤街浪徒 提交于 2019-12-24 14:04:22

问题


Recently I have tried Django-Compressor. It's awesome and i like it too much, but i am having some troubles with offline compression (COMPRESS_OFFLINE = True) and template tags.

I have {{ django_vars }} and {% django_tags %} inside my JS code and i guess Google Clousure compiler (the filter what i'm using with Django-Compressor) doesn't know to identify them. In fact, I think Django template structures like {% if something %} are deleted.

How can i do to keep all this template vars/tags in my code JS after compressing?

Thanks mates.

Edit: Finally, i discovered all problems that i got using COMPRESS_OFFLINE, they all occurred due to a bug. They were not about Django syntax inside of JS code. The bug always appeared when you tried to compress JS code inside of a file .html, not a external JS. It failed with all parsers and all compilers/compressors.

Now, although i like more django-compressor than django-pipeline, i'm using this last one. At this moment, no problem reported with compression.

Thanks to all who tried to help me.


回答1:


Have you tried that? JS compiler of Django Compressor gets into work AFTER template nodes are rendered, IMO. Thus the {{ django_vars }} or {% django_tags %} are already replaced by their outputs in templates before being compressed.

If {{ django_vars }} or {% django_tags %} are changed per-view/template. It can not be compress to one piece of code. You'd better to move those parts from main JS code blocks to JS block and compress it separately.



来源:https://stackoverflow.com/questions/11172329/django-compressor-and-template-tags-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!