3

As described in their docs here, I am configured my application to serve static files locally.

The only problem I am facing is that I am unable to determine if it is django or whitenoise which is serving static files?

Steps which I followed:

pip install whitenoise # install whitenoise
pip install brotlipy # install brotlipy for compression

INSTALLED_APPS = [

# default django apps
'django.contrib.messages',

# REMOVE IN PRODUCTION
# See: http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
'whitenoise.runserver_nostatic',

'django.contrib.staticfiles',
# other apps
]


# add white-noise middleware

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',

    # static files serving
    'whitenoise.middleware.WhiteNoiseMiddleware',


    'django.contrib.sessions.middleware.SessionMiddleware',
     # other middlewares
]


# add staticfiles 
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# run collecstatic
python manage.py collectstatic

# restart the server
python manage.py runserver

# This gives me following

[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/css/print.css HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/chartkick.js HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/js/jquery_pre.js HTTP/1.1" 304 0

However, I expect something like this,

[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/css/print.636363s6s.css HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/chartkick.2623678s3cdce3.js HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/js/jquery_pre.6276gdg3js8j.js HTTP/1.1" 304 0

How can I check if whitenoise is working and that it is serving static files?

inquilabee
  • 713
  • 1
  • 11
  • 23

2 Answers2

1

Since it's been quite a while since you asked this question, I imagine you've found an answer by now. But if anyone else stumbles on it, I've found that Django won't serve static files if you have DEBUG=False. So if you have that setting and you're still seeing static, it's likely being done by whitenoise.

carousallie
  • 776
  • 1
  • 7
  • 25
0

This is an old question, but I'm answering here for posterity. When running python manage.py runserver, the runserver takes over management of static files. However, you can run python manage.py runserver --nostatic or add "whitenoise.runserver_nostatic" as the first in the INSTALLED_APPS in your setting.py, see here

John Kitonyo
  • 2,109
  • 1
  • 14
  • 17