[英]Whitenoise to serve static files locally
正如此處的文檔中所述,我將應用程序配置為在本地提供靜態文件。
我面臨的唯一問題是我無法確定是 django 還是 whitenoise 提供靜態文件?
我遵循的步驟:
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
如何檢查白噪聲是否正常工作以及它是否提供靜態文件?
由於您問這個問題已經有一段時間了,我想您現在已經找到了答案。 但是如果其他人偶然發現它,我發現如果您有DEBUG=False
,Django 將不會提供靜態文件。 因此,如果您具有該設置並且仍然看到靜態,則很可能是由白噪聲造成的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.