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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.