[英]Whitenoise to serve static files locally
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?我面临的唯一问题是我无法确定是 django 还是 whitenoise 提供静态文件?
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
.但是如果其他人偶然发现它,我发现如果您有
DEBUG=False
,Django 将不会提供静态文件。 So if you have that setting and you're still seeing static, it's likely being done by whitenoise.因此,如果您具有该设置并且仍然看到静态,则很可能是由白噪声造成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.