1

All,

I am using django-compressor and it is working for my development environment (pure Django) but not my production environment (Django under Apache, hosted by WebFaction). Here are the relevant details:

settings.py:

STATIC_ROOT = "/path/to/my/static/files/"
STATIC_URL = '/static/'
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_ROOT = STATIC_ROOT + "my_app_name/"
COMPRESS_PRECOMPILERS = (
    ('text/less', 'lessc {infile} {outfile}'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)

some_template.html:

{% load staticfiles %}
{% load compress %}
<html>
  <head>
    {% compress css %}
      <link rel="stylesheet" type="text/less" media="all" href="{% static 'my_app/less/my_app.less' %}" />
    {% endcompress %}
  </head>
  <body>
    <div class="my_class">hello world</div>
  </body>
</html>

I run python manage.py compress && python manage.py collectstatic to make sure the "my_app.less" file above is compiled, compressed, and copied correctly.

As I said, in my development environment this works fine. The server makes a call to "//localhost:8000/static/CACHE/css/1d4e9429eac4.css" and returns the file at "/path/to/my/static/files/my_app_name/CACHE/css/1d4e9429eac4.css".

But in production, that same URL "//my.domain.com/static/CACHE/css/1d4e9429eac4.css" returns a 404 Not Found error. The file exists locally at "/path/to/my/static/files/my_app_name/CACHE/css/1d4e9429eac4.css".

I've noticed that if I manually goto "//my.domain.com/static/my_app_name/CACHE/css/1d4e9429eac4.css" (note the addition of "my_app_name") then the file is found.

My question is, why is it behaving differently on the two servers? Which is the correct behavior? And how can I ensure that compression works in both cases?

Thanks.

trubliphone
  • 4,132
  • 3
  • 42
  • 66
  • I'd guess that you have a mismatching or non-existent `alias` in your apache config that should be something like `Alias /static /path/to/my/static/files/` – Ross Rogers Dec 03 '15 at 19:38
  • @RossRogers: I will look into that now, but I am able to find non-compressed static files just fine. – trubliphone Dec 03 '15 at 19:46
  • Where is the compressed css located? `find /var/www/ -name '1d4e9429eac4.css'` – Ross Rogers Dec 03 '15 at 19:47
  • non-compressed css is at: "/path/to/my/static/files/my_app_name/css" compressed css is at: "/path/to/my/static/files/my_app_name/CACHED/css" – trubliphone Dec 03 '15 at 19:49
  • Ok, how about this: `Alias /static/CACHE/ /path/to/my/static/files/my_app_name/CACHE/` . If you have multiple [virtual hosts](https://httpd.apache.org/docs/2.4/vhosts/examples.html), put it in `my_app_name`'s virtual host. [Alias docs are here](https://httpd.apache.org/docs/2.4/mod/mod_alias.html) – Ross Rogers Dec 03 '15 at 19:55
  • @RossRogers: That really seems like it should work, but I am getting the same error. I suspect that the issue has something to do w/ separating out my main Django project and my static files into two separate applications on webfaction. The former uses Apache, the latter does not. Thank you for your help, I have some Django-specific ideas to try out. – trubliphone Dec 03 '15 at 20:05

0 Answers0