Whitenoise在本地提供静态文件

时间:2018-04-10 06:53:56

标签: python django whitenoise

正如他们的文档here中所述,我将我的应用程序配置为提供静态文件本地

我面临的唯一问题是我无法确定它是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

如何检查whitenoise是否正常工作以及是否正在提供静态文件?

1 个答案:

答案 0 :(得分:0)

自从您问这个问题已有很长时间以来,我想您已经找到答案了。但是,如果有人发现它,我发现如果您使用DEBUG=False,Django将不会提供静态文件。因此,如果您具有该设置并且仍然看到静态,则很可能是白噪声造成的。

相关问题