How to use django compressor with apache?

I use Django Compressor to manage my coffee and smaller coffee files, as well as for development, but I had some problems to get it working for my production deployment.

My idea is to have apache to host static files, possibly on another server. I install COMPRESS_OFFLINE = Truein a file settings.py.

Then i do the following

  • python manage.py compress- This fills the directory CACHEin my directory static, where all static files will be collected.
  • python manage.py collectstatic- collects static files from all applications of my project (some of which do not use a compressor) in my directory static.
  • Copy the directory staticsomewhere where apache will be hosted. And configure apache to serve files.
  • Change the variable static_urlin the file settings.pyto point to a static server.

If I open any page, I get the following error on my server, this seems to happen when I have DEBUG = Falseand COMPRESS_OFFLINE = Truein my file settings.py:

TemplateSyntaxError: Caught OfflineGenerationError when rendering: You have offline compression disabled, but the key "777ba26736d046ab043dc151e7e9a060" is not in the offline manifest. You may need to run "python manage.py compress".

When I check the directory static/CACHE, I confirm that it says an error, this is my file manifest.json:

{
  "6189b8598993d1cbdbd35d4dfd1a6711": "<script type=\"text/javascript\" src=\"http://192.168.1.123/CACHE/js/2f6ca6616bd6.js\"></script>",
  "5c66dbed0e5b766c6e32773cd8585f3c": "<link rel=\"stylesheet\" href=\"http://192.168.1.123/CACHE/css/154d95903951.css\" type=\"text/css\" />"
}

CACHE python manage.py compress, , , .

, , . ? ?

.

+5
3

,

OfflineGenerationError: , "4971a40e3b459a8cda8287a7f7caa96d". , "python manage.py compress"

, , . , .

+15

, django-compressor 1.1.2, {% static "..." %}.

dev- django-compressor :

pip install django_compressor == dev

.

+3

David Wolfe is absolutely right: I had to dig out all of my code to get rid of {% trans ... etc. I do it like this:

<script>
window.__enter_email = "{% trans "Enter correct email" %}"
window.__url = "{% url "shop:go" %}"
</script>
{% compress js %}
<script>
$("#bla")..... window.__enter_email ...
</script>
{% endcompress %}

Hope it helps someone!

0
source

All Articles