Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django not fetching compressed files when Debug set to False #348

Closed
amosjyng opened this issue Dec 22, 2012 · 5 comments
Closed

Django not fetching compressed files when Debug set to False #348

amosjyng opened this issue Dec 22, 2012 · 5 comments

Comments

@amosjyng
Copy link

So I got django-compressor working in development with Debug = False. However, once I set Debug = True, django-compressor seems to generate the correct URLs, files, and everything, but Django itself returns a 404 for those files.

I have

STATIC_ROOT = os.path.join(PROJECT_DIR, "static_media")

and inside the static_media folder in my project, I can indeed see the CACHE/css/bfdeac875f7a.css file that was created by the compressor.

Inside the generated HTML file, I can also see

<link rel="stylesheet" href="/static/CACHE/css/bfdeac875f7a.css" type="text/css" />

but when the page is loaded, runserver says:

[21/Dec/2012 22:28:44] "GET /static/CACHE/css/bfdeac875f7a.css HTTP/1.1" 404 276

Am I missing something? I have already

  • added 'django.core.context_processors.static', to TEMPLATE_CONTEXT_PROCESSORS
  • added 'compressor.finders.CompressorFinder', to STATICFILES_FINDERS
  • added 'compressor', to INSTALLED_APPS

Thanks!

@diox
Copy link
Member

diox commented Dec 22, 2012

Hi,

We are going to need a little more info about your setup to help you:

  • Your COMPRESS_* settings, STATIC_URL setting, STATICFILES_* settings
  • Is staticfiles in your INSTALLED_APPS ?
  • What's your version of Django ?
  • Do other static files work correctly ? You are using the runserver to serve them, right ?

Thanks

@amosjyng
Copy link
Author

Hi,

I am using Django 1.4.3, with the following settings:

...

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(PROJECT_DIR, "static_media")

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(PROJECT_DIR, "static"),
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
    'compressor.finders.CompressorFinder',
)

COMPRESS_PRECOMPILERS = (
    ('text/coffeescript', 'coffee --compile --stdio'),
    ('text/x-scss', 'sass --scss {infile} {outfile}'),
)

...

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    ...
    'compressor',
    ...
)

...

Files that I manually put within static_media are inaccessible from the /static/ url as well, so I must have not congfigured staticfiles correctly... I did also migrate from Django 1.3, if that matters. Would you have a hunch as to what I should try?

@amosjyng
Copy link
Author

Also, runserver successfully fetches the files in my static_media folder when Debug is true, but fails when it is false...

@diox
Copy link
Member

diox commented Dec 22, 2012

Sorry, can't believe I missed that earlier : I somehow read that you had problems when DEBUG is True.

Anyway. When DEBUG = False, your runserver will, by default, refuse to serve staticfiles itself, because of performance and security issues. This is to prevent you from using this in production. To be able to properly test your staticfiles locally when DEBUG is False, you need to pass the --insecure flag to runserver, like documented here: https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#django-admin-option---insecure

Does that fix your issue ?

@amosjyng
Copy link
Author

Oh gosh, my bad. I had inadvertently switched "True" and "False" in my original question, sorry for the confusion!

And thanks so much, that does solve the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants