gpt4 book ai didi

python - Whitenoise 在本地提供静态文件

转载 作者:行者123 更新时间:2023-12-02 05:41:31 30 4
gpt4 key购买 nike

如其文档中所述 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

如何检查白噪声是否正在工作以及它是否正在提供静态文件?

最佳答案

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

关于python - Whitenoise 在本地提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49747211/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com